Skip to content

Commit f784650

Browse files
committed
tests: Run templateTestList entries as subtests
This prevents one failed test case from aborting attempts for the other test cases, and it makes it easier to iterate on a particular test case.
1 parent 85030ce commit f784650

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

internal/template/template_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ type templateTestList []struct {
2020
func (tests templateTestList) run(t *testing.T, prefix string) {
2121
for n, test := range tests {
2222
tmplName := fmt.Sprintf("%s-test-%d", prefix, n)
23-
tmpl := template.Must(newTemplate(tmplName).Parse(test.tmpl))
24-
25-
var b bytes.Buffer
26-
err := tmpl.ExecuteTemplate(&b, tmplName, test.context)
27-
if err != nil {
28-
t.Fatalf("Error executing template: %v (test %s)", err, tmplName)
29-
}
30-
31-
got := b.String()
32-
if test.expected != got {
33-
t.Fatalf("Incorrect output found; expected %s, got %s (test %s)", test.expected, got, tmplName)
34-
}
23+
t.Run(tmplName, func(t *testing.T) {
24+
tmpl := template.Must(newTemplate(tmplName).Parse(test.tmpl))
25+
26+
var b bytes.Buffer
27+
err := tmpl.ExecuteTemplate(&b, tmplName, test.context)
28+
if err != nil {
29+
t.Fatalf("Error executing template: %v (test %s)", err, tmplName)
30+
}
31+
32+
got := b.String()
33+
if test.expected != got {
34+
t.Fatalf("Incorrect output found; expected %s, got %s (test %s)", test.expected, got, tmplName)
35+
}
36+
})
3537
}
3638
}
3739

0 commit comments

Comments
 (0)