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