github.com/zaquestion/lab@v0.25.1/cmd/milestone_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"os/exec"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_milestoneCmd(t *testing.T) {
    12  	t.Parallel()
    13  	repo := copyTestRepo(t)
    14  	t.Run("prepare", func(t *testing.T) {
    15  		cmd := exec.Command("sh", "-c", labBinaryPath+` milestone list lab-testing | grep -q 'test-milestone' && `+labBinaryPath+` milestone delete test-milestone`)
    16  		cmd.Dir = repo
    17  
    18  		b, err := cmd.CombinedOutput()
    19  		if err != nil {
    20  			t.Log(string(b))
    21  			//t.Fatal(err)
    22  		}
    23  	})
    24  	t.Run("create", func(t *testing.T) {
    25  		cmd := exec.Command(labBinaryPath, "milestone", "create", "lab-testing", "test-milestone")
    26  		cmd.Dir = repo
    27  
    28  		b, _ := cmd.CombinedOutput()
    29  		if strings.Contains(string(b), "403 Forbidden") {
    30  			t.Skip("No permission to change milestones, skipping")
    31  		}
    32  
    33  		cmd = exec.Command(labBinaryPath, "milestone", "list", "lab-testing")
    34  		cmd.Dir = repo
    35  
    36  		b, err := cmd.CombinedOutput()
    37  		out := string(b)
    38  		if err != nil {
    39  			t.Log(out)
    40  			//t.Fatal(err)
    41  		}
    42  		require.Contains(t, out, "test-milestone")
    43  	})
    44  	t.Run("delete", func(t *testing.T) {
    45  		cmd := exec.Command(labBinaryPath, "milestone", "delete", "lab-testing", "test-milestone")
    46  		cmd.Dir = repo
    47  
    48  		_ = cmd.Run()
    49  
    50  		cmd = exec.Command(labBinaryPath, "milestone", "list", "lab-testing")
    51  		cmd.Dir = repo
    52  
    53  		b, err := cmd.CombinedOutput()
    54  		out := string(b)
    55  		if err != nil {
    56  			t.Log(out)
    57  			//t.Fatal(err)
    58  		}
    59  		require.NotContains(t, out, "test-milestone")
    60  	})
    61  }