diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index 6bb00c137..8b0e2b101 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -1,10 +1,14 @@ package templates import ( + "context" + "errors" "maps" "slices" "testing" + "github.com/evcc-io/evcc/plugin/auth" + "github.com/evcc-io/evcc/util" "go.yaml.in/yaml/v4" ) @@ -34,6 +38,35 @@ func test(t *testing.T, tmpl Template, values map[string]any, cb func(values map cb(values) } +func testAuth(other map[string]any) error { + if len(other) == 0 { + return nil + } + + var cc struct { + Type string + Params []string + } + + if err := util.DecodeOther(other, &cc); err != nil { + return err + } + + params := make(map[string]any) + for _, p := range cc.Params { + params[p] = "foo" + } + + _, err := auth.NewFromConfig(context.TODO(), cc.Type, params) + + // ConfigError indicates invalid parameters in mapstructure decode + if ce := new(util.ConfigError); errors.As(err, &ce) { + return err + } + + return nil +} + func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values map[string]any)) { t.Parallel() @@ -60,6 +93,11 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values // https://github.com/evcc-io/evcc/pull/10272 - override example IP (192.0.2.2) values["host"] = "localhost" + // test auth configuration + if err := testAuth(tmpl.TemplateDefinition.Auth); err != nil { + t.Error("authorization:", err) + } + usages := tmpl.Usages() if len(usages) == 0 { t.Run(tmpl.Template, func(t *testing.T) { diff --git a/vehicle/template_test.go b/vehicle/template_test.go index 07f6ac96d..03c485ed4 100644 --- a/vehicle/template_test.go +++ b/vehicle/template_test.go @@ -26,7 +26,7 @@ var acceptable = []string{ "unexpected status: 401", "discussions/17501", // Tesla "login failed: code not found", // Polestar - "empty instance type- check for missing usage", // Merces + "empty instance type- check for missing usage", // Mercedes } func TestTemplates(t *testing.T) {