Skip to content

Commit

Permalink
checklist: Add test to avoid filtering separators
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
joestringer committed Nov 7, 2024
1 parent 91e5161 commit 8119cde
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd/checklist/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package checklist
import (
"os"
"path/filepath"
"regexp"
"testing"

"github.com/go-quicktest/qt"
Expand Down Expand Up @@ -104,3 +105,37 @@ func Test_prepareChecklist(t *testing.T) {
})
}
}

func Test_templateToRequest(t *testing.T) {
cfg := ChecklistConfig{
TargetVer: "v1.10.0-pre.0",
}
testdataPath := filepath.Join("..", "..", "testdata", "checklist")

paths, err := filepath.Glob(filepath.Join(testdataPath, "*.input"))
if err != nil {
t.Fatal(err)
}

for _, path := range paths {
_, filename := filepath.Split(path)
testname := filename[:len(filename)-len(filepath.Ext(path))]

t.Run(testname, func(t *testing.T) {
source, err := os.ReadFile(path)
qt.Assert(t, qt.IsNil(err), qt.Commentf("failed to read input template: %w", err))

barRe := regexp.MustCompile(`---`)
expBarCount := len(barRe.FindAll(source, -1)) - 2 // Exclude the metadata section at the top

cl, err := prepareChecklist(source, cfg)
qt.Assert(t, qt.IsNil(err), qt.Commentf("failed to render checklist: %w", err))

req, err := templateToRequest(cl)
qt.Assert(t, qt.IsNil(err), qt.Commentf("failed to translate checklist into GitHub request: %w", err))

barCount2 := barRe.FindAllString(*req.Body, -1)
qt.Assert(t, qt.Equals(len(barCount2), expBarCount), qt.Commentf("template unexpectedly trimmed valid horizontal separators"))
})
}
}

0 comments on commit 8119cde

Please sign in to comment.