github.com/zaquestion/lab@v0.25.1/cmd/issue_create_test.go (about) 1 package cmd 2 3 import ( 4 "net/url" 5 "os/exec" 6 "path" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func Test_issueCreate(t *testing.T) { 14 repo := copyTestRepo(t) 15 cmd := exec.Command(labBinaryPath, "issue", "create", "lab-testing", 16 "-m", "issue title") 17 cmd.Dir = repo 18 19 b, err := cmd.CombinedOutput() 20 if err != nil { 21 t.Fatalf("Error creating issue: %s (%s)", string(b), err) 22 } 23 out := getAppOutput(b)[0] 24 25 require.Contains(t, out, "https://gitlab.com/lab-testing/test/-/issues/") 26 27 // Get the issue ID from the returned URL and close the issue. 28 u, err := url.Parse(out) 29 require.NoError(t, err, "Error parsing URL") 30 id := path.Base(u.Path) 31 32 cmd = exec.Command(labBinaryPath, "issue", "close", "lab-testing", id) 33 cmd.Dir = repo 34 b, err = cmd.CombinedOutput() 35 require.NoError(t, err, "Error closing issue %s: %s", id, string(b)) 36 } 37 38 func Test_issueMsg(t *testing.T) { 39 tests := []struct { 40 Name string 41 Msgs []string 42 ExpectedTitle string 43 ExpectedBody string 44 }{ 45 { 46 Name: "Using messages", 47 Msgs: []string{"issue title", "issue body", "issue body 2"}, 48 ExpectedTitle: "issue title", 49 ExpectedBody: "issue body\n\nissue body 2", 50 }, 51 { 52 Name: "From Editor", 53 Msgs: nil, 54 ExpectedTitle: "This is the default issue template for lab", 55 ExpectedBody: "", 56 }, 57 } 58 for _, test := range tests { 59 t.Run(test.Name, func(t *testing.T) { 60 test := test 61 t.Parallel() 62 title, body, err := issueMsg("default", test.Msgs) 63 if err != nil { 64 t.Fatal(err) 65 } 66 assert.Equal(t, test.ExpectedTitle, title) 67 assert.Equal(t, test.ExpectedBody, body) 68 }) 69 } 70 } 71 72 func Test_issueText(t *testing.T) { 73 t.Parallel() 74 text, err := issueText("default") 75 if err != nil { 76 t.Fatal(err) 77 } 78 require.Equal(t, ` 79 80 This is the default issue template for lab 81 # Write a message for this issue. The first block 82 # of text is the title and the rest is the description.`, text) 83 84 }