Configurable extensions for template parser

This commit is contained in:
Katrina Verey
2022-04-21 18:28:13 -04:00
parent 9d5491c2e2
commit bcae65770a
5 changed files with 42 additions and 10 deletions

View File

@@ -81,7 +81,7 @@ func TestTemplateFiles(t *testing.T) {
{
name: "rejects non-.template.yaml files",
paths: []string{"testdata/ignore.yaml"},
wantErr: "file testdata/ignore.yaml did not have required extension .template.yaml",
wantErr: "file testdata/ignore.yaml does not have any of permitted extensions [.template.yaml]",
},
}
for _, tt := range tests {
@@ -114,6 +114,23 @@ func TestTemplateFiles(t *testing.T) {
}
}
func TestTemplateParser_WithExtensions(t *testing.T) {
p := parser.TemplateFiles("testdata").WithExtensions(".json")
templates, err := p.Parse()
require.NoError(t, err)
require.Len(t, templates, 2)
p = p.WithExtensions(".yaml")
templates, err = p.Parse()
require.NoError(t, err)
require.Len(t, templates, 3)
p = p.WithExtensions(".yaml", ".json")
templates, err = p.Parse()
require.NoError(t, err)
require.Len(t, templates, 5)
}
func TestTemplateStrings(t *testing.T) {
tests := []struct {
name string