Skip to content

Commit 5f044aa

Browse files
joestringeraanm
authored andcommitted
checklist: Add test to avoid filtering separators
There was a bug in the checklist substitution which caused issue content following a horizontal separator to be discarded rather than posted into the target issue. Add a test to catch this case. Signed-off-by: Joe Stringer <[email protected]>
1 parent 9f43217 commit 5f044aa

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

cmd/checklist/template_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package checklist
66
import (
77
"os"
88
"path/filepath"
9+
"regexp"
910
"testing"
1011

1112
"github.com/stretchr/testify/assert"
@@ -104,3 +105,37 @@ func Test_prepareChecklist(t *testing.T) {
104105
})
105106
}
106107
}
108+
109+
func Test_templateToRequest(t *testing.T) {
110+
cfg := ChecklistConfig{
111+
TargetVer: "v1.10.0-pre.0",
112+
}
113+
testdataPath := filepath.Join("..", "..", "testdata", "checklist")
114+
115+
paths, err := filepath.Glob(filepath.Join(testdataPath, "*.input"))
116+
if err != nil {
117+
t.Fatal(err)
118+
}
119+
120+
for _, path := range paths {
121+
_, filename := filepath.Split(path)
122+
testname := filename[:len(filename)-len(filepath.Ext(path))]
123+
124+
t.Run(testname, func(t *testing.T) {
125+
source, err := os.ReadFile(path)
126+
assert.Nil(t, err, "failed to read input template: ", err)
127+
128+
barRe := regexp.MustCompile(`---`)
129+
expBarCount := len(barRe.FindAll(source, -1)) - 2 // Exclude the metadata section at the top
130+
131+
cl, err := prepareChecklist(source, cfg)
132+
assert.Nil(t, err, "failed to render checklist: ", err)
133+
134+
req, err := templateToRequest(cl)
135+
assert.Nil(t, err, "failed to translate checklist into GitHub request: ", err)
136+
137+
barCount2 := barRe.FindAllString(*req.Body, -1)
138+
assert.Equal(t, len(barCount2), expBarCount, "template unexpectedly removed valid horizontal separators")
139+
})
140+
}
141+
}

0 commit comments

Comments
 (0)