package templtest import ( "testing" "git.buddy.wtf/lib/tmpl" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" ) func TestList(t *testing.T) { type testcase struct { Name string tmpl.Templates Expected []string Err error } tt := []testcase{ { Name: "list all files on empty config ", Templates: tmpl.Templates{FS: data}, Expected: []string{ "data/broken.invalid", "data/broken.template", "data/first/1/bar.txt.tmpl", "data/first/1/foo.txt.tmpl", "data/first/2/item.txt.tmpl", "data/first/2/list.txt.tmpl", "data/first/index.txt.tmpl", "data/first/static.txt", "data/index.html.tmpl", "data/index.txt.tmpl", "data/second/1/list.html.tmpl", "data/second/1/single.html.tmpl", "data/second/index.html.tmpl", "data/second/static.txt", }, }, { Name: "only list templates with matching suffix with suffix not in name", Templates: tmpl.Templates{ FS: data, Root: "data", Suffix: "tmpl", }, Expected: []string{ "first/1/bar.txt", "first/1/foo.txt", "first/2/item.txt", "first/2/list.txt", "first/index.txt", "index.html", "index.txt", "second/1/list.html", "second/1/single.html", "second/index.html", }, }, } for _, tc := range tt { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() a := assert.New(t) actual, err := tc.Templates.List() errorIs(a, err, tc.Err) a.Empty(cmp.Diff(tc.Expected, actual)) }) } }