github.com/zaquestion/lab@v0.25.1/cmd/note_common_test.go (about) 1 package cmd 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 // NOTE: tests for other functions, like createNote, are part of the 11 // issue_note test suite. 12 13 func Test_noteMsg(t *testing.T) { 14 tests := []struct { 15 Name string 16 Msgs []string 17 ExpectedBody string 18 }{ 19 { 20 Name: "Using messages", 21 Msgs: []string{"note paragraph 1", "note paragraph 2"}, 22 ExpectedBody: "note paragraph 1\n\nnote paragraph 2", 23 }, 24 { 25 Name: "From Editor", 26 Msgs: nil, 27 ExpectedBody: "", // this is not a great test 28 }, 29 } 30 for _, test := range tests { 31 t.Run(test.Name, func(t *testing.T) { 32 test := test 33 t.Parallel() 34 body, err := noteMsg(test.Msgs, false, 1, "OPEN", "", "\n") 35 if err != nil { 36 t.Fatal(err) 37 } 38 assert.Equal(t, test.ExpectedBody, body) 39 }) 40 } 41 } 42 43 func Test_noteText(t *testing.T) { 44 t.Parallel() 45 tmpl := noteGetTemplate(true, "") 46 text, err := noteText(1701, "OPEN", "", "\n", tmpl) 47 if err != nil { 48 t.Fatal(err) 49 } 50 require.Equal(t, ` 51 52 # This comment is being applied to OPEN Merge Request 1701. 53 # Comment lines beginning with '#' are discarded.`, text) 54 }