evcc-io/charger/template_test.go
Andreas Linde fb1d6f552f
Remove dependency from config repo (#2182)
The templates infrastructure replaces this
2022-01-01 17:50:32 +01:00

69 lines
1.7 KiB
Go

package charger
import (
"testing"
"github.com/evcc-io/evcc/util/templates"
"github.com/evcc-io/evcc/util/test"
"github.com/thoas/go-funk"
)
var acceptable = []string{
"invalid plugin type: ...",
"missing mqtt broker configuration",
"mqtt not configured",
"invalid charger type: nrgkick-bluetooth",
"NRGKick bluetooth is only supported on linux",
"invalid pin:",
"hciconfig provided no response",
"connect: no route to host",
"connect: connection refused",
"error connecting: Network Error",
"i/o timeout",
"recv timeout",
"(Client.Timeout exceeded while awaiting headers)",
"can only have either uri or device", // modbus
"sponsorship required, see https://github.com/evcc-io/evcc#sponsorship",
"eebus not configured",
"unexpected status: 400", // easee
}
func TestChargerTemplates(t *testing.T) {
test.SkipCI(t)
for _, tmpl := range templates.ByClass(templates.Charger) {
tmpl := tmpl
// set default values for all params
values := tmpl.Defaults(true)
// set the template value which is needed for rendering
values["template"] = tmpl.Template
// set modbus default test values
if values[templates.ParamModbus] != nil {
modbusChoices := tmpl.ModbusChoices()
if funk.ContainsString(modbusChoices, templates.ModbusChoiceTCPIP) {
values[templates.ModbusTCPIP] = true
} else {
values[templates.ModbusRS485TCPIP] = true
}
}
t.Run(tmpl.Template, func(t *testing.T) {
t.Parallel()
b, values, err := tmpl.RenderResult(true, values)
if err != nil {
t.Logf("%s: %s", tmpl.Template, b)
t.Error(err)
}
_, err = NewFromConfig("template", values)
if err != nil && !test.Acceptable(err, acceptable) {
t.Logf("%s", tmpl.Template)
t.Error(err)
}
})
}
}