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