github.com/ianfoo/lab@v0.9.5-0.20180123060006-5ed79f2ccfc7/cmd/issueCreate_test.go (about) 1 package cmd 2 3 import ( 4 "os/exec" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func Test_issueCreate(t *testing.T) { 12 t.Parallel() 13 repo := copyTestRepo(t) 14 cmd := exec.Command("../lab_bin", "issue", "create", "lab-testing", 15 "-m", "issue title") 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 require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/issues/") 25 } 26 27 func Test_issueMsg(t *testing.T) { 28 tests := []struct { 29 Name string 30 Msgs []string 31 ExpectedTitle string 32 ExpectedBody string 33 }{ 34 { 35 Name: "Using messages", 36 Msgs: []string{"issue title", "issue body", "issue body 2"}, 37 ExpectedTitle: "issue title", 38 ExpectedBody: "issue body\n\nissue body 2", 39 }, 40 { 41 Name: "From Editor", 42 Msgs: nil, 43 ExpectedTitle: "I am the issue tmpl", 44 ExpectedBody: "", 45 }, 46 } 47 for _, test := range tests { 48 t.Run(test.Name, func(t *testing.T) { 49 test := test 50 t.Parallel() 51 title, body, err := issueMsg(test.Msgs) 52 if err != nil { 53 t.Fatal(err) 54 } 55 assert.Equal(t, test.ExpectedTitle, title) 56 assert.Equal(t, test.ExpectedBody, body) 57 }) 58 } 59 } 60 61 func Test_issueText(t *testing.T) { 62 t.Parallel() 63 text, err := issueText() 64 if err != nil { 65 t.Fatal(err) 66 } 67 require.Equal(t, ` 68 69 I am the issue tmpl 70 # Write a message for this issue. The first block 71 # of text is the title and the rest is the description.`, text) 72 73 }