package webutil import ( "bytes" "embed" "html/template" "strings" "testing" ) //go:embed all:test-templates var testFS embed.FS func TestParseTemplateSet(t *testing.T) { funcs := template.FuncMap{"join": strings.Join} m := ParseTemplateSet(funcs, testFS) type TestCase struct { Key string Data any Out string } cases := []TestCase{ { Key: "/home.html", Data: "DATA", Out: "

HOME!

", }, { Key: "/about.html", Data: "DATA", Out: "

DATA

", }, { Key: "/contact.html", Data: []string{"a", "b", "c"}, Out: "

a,b,c

", }, } for _, tc := range cases { b := &bytes.Buffer{} m[tc.Key].Execute(b, tc.Data) out := strings.TrimSpace(b.String()) if out != tc.Out { t.Fatalf("%s != %s", out, tc.Out) } } }