forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
template_test.go
68 lines (58 loc) · 2.2 KB
/
template_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package vehicle
import (
"testing"
"github.com/evcc-io/evcc/util/templates"
"github.com/evcc-io/evcc/util/test"
)
var acceptable = []string{
"invalid plugin type: ...",
"missing mqtt broker configuration",
"received status code 404 (INVALID PARAMS)", // Nissan
"missing personID",
"401 Unauthorized",
"unexpected length",
"i/o timeout",
"no such host",
"network is unreachable",
"Missing required parameter", // Renault
"error connecting: Network Error",
"unexpected status: 401",
"could not obtain token", // Porsche
"missing credentials", // Tesla
"invalid vehicle type: hyundai",
"invalid vehicle type: kia",
"missing user, password or serial", // Niu
"missing credentials id", // Tronity
"missing access and/or refresh token, use `evcc token` to create", // Tesla
"login failed: Unauthorized: Authentication Failed", // Nissan
"login failed: no auth code", // Porsche
"login failed: unexpected status: 400", // Smart
"invalid_client:Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)", // BMW, Mini
"login failed: oauth2: cannot fetch token: 400 Bad Request Response: {\"error\":\"invalid_request\",\"error_description\":\"Missing parameter, 'username'\"}", // Opel, DS, Citroen, PSA
"401: Unauthorized: Invalid credentials", // Volvo
}
func TestVehicleTemplates(t *testing.T) {
test.SkipCI(t)
for _, tmpl := range templates.ByClass(templates.Vehicle) {
tmpl := tmpl
// set default values for all params
values := tmpl.Defaults(templates.TemplateRenderModeUnitTest)
// set the template value which is needed for rendering
values["template"] = tmpl.Template
t.Run(tmpl.Template, func(t *testing.T) {
t.Parallel()
b, values, err := tmpl.RenderResult(templates.TemplateRenderModeUnitTest, values)
if err != nil {
t.Logf("Template: %s", tmpl.Template)
t.Logf("%s", string(b))
t.Error(err)
}
_, err = NewFromConfig("template", values)
if err != nil && !test.Acceptable(err, acceptable) {
t.Logf("Template: %s", tmpl.Template)
t.Logf("%s", string(b))
t.Error(err)
}
})
}
}