parent
8eca79a675
commit
785ae1a417
9 changed files with 42 additions and 132 deletions
|
|
@ -7,9 +7,18 @@ import (
|
|||
)
|
||||
|
||||
func TestChargers(t *testing.T) {
|
||||
acceptable := []string{
|
||||
"invalid plugin type: ...",
|
||||
"mqtt not configured",
|
||||
"NRGKick bluetooth is only supported on linux",
|
||||
"invalid pin:",
|
||||
"connect: no route to host",
|
||||
"connect: connection refused",
|
||||
}
|
||||
|
||||
for _, tmpl := range test.ConfigTemplates("charger") {
|
||||
_, err := NewFromConfig(tmpl.Type, tmpl.Config)
|
||||
if err != nil && !test.Acceptable("charger", err) {
|
||||
if err != nil && !test.Acceptable(err, acceptable) {
|
||||
t.Logf("%s", tmpl.Name)
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// skipCI skips testing if CI is set
|
||||
func skipCI(t *testing.T) {
|
||||
if os.Getenv("CI") != "" {
|
||||
t.Skip("Skipping testing in CI environment")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistConfig(t *testing.T) {
|
||||
skipCI(t)
|
||||
|
||||
file := "../evcc.dist.yaml"
|
||||
yaml, err := os.Open(file)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
viper.SetConfigType("yaml")
|
||||
if err := viper.ReadConfig(yaml); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// check config does not contain surplus keys
|
||||
var conf config
|
||||
if err := viper.UnmarshalExact(&conf); err != nil {
|
||||
log.FATAL.Fatalf("failed parsing config file %s: %v", cfgFile, err)
|
||||
}
|
||||
|
||||
// setup mqtt
|
||||
if conf.Mqtt.Broker != "" {
|
||||
configureMQTT(conf.Mqtt)
|
||||
}
|
||||
|
||||
// check config is valid
|
||||
_ = loadConfig(conf)
|
||||
}
|
||||
|
||||
func TestMeterConfig(t *testing.T) {
|
||||
yaml := `
|
||||
meters:
|
||||
- name: pv
|
||||
type: exec # mqtt will fail due to missing global
|
||||
power: topic
|
||||
- name: charge
|
||||
type: exec
|
||||
power: script
|
||||
`
|
||||
viper.SetConfigType("yaml")
|
||||
if err := viper.ReadConfig(bytes.NewBuffer([]byte(yaml))); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func TestChargerConfig(t *testing.T) {
|
||||
yaml := `
|
||||
chargers:
|
||||
- name: test
|
||||
type: configurable
|
||||
status:
|
||||
type: script
|
||||
cmd: script
|
||||
enable:
|
||||
type: script
|
||||
cmd: script
|
||||
enabled:
|
||||
type: script
|
||||
cmd: script
|
||||
maxCurrent:
|
||||
type: script
|
||||
cmd: script
|
||||
- name: wallbe
|
||||
type: wallbe
|
||||
uri: 192.168.0.8:502
|
||||
`
|
||||
viper.SetConfigType("yaml")
|
||||
if err := viper.ReadConfig(bytes.NewBuffer([]byte(yaml))); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
14
errors.yaml
14
errors.yaml
|
|
@ -1,14 +0,0 @@
|
|||
meter:
|
||||
- "invalid plugin type: ..."
|
||||
- dial tcp
|
||||
- not a SunSpec device
|
||||
charger:
|
||||
- "invalid plugin type: ..."
|
||||
- mqtt not configured
|
||||
- NRGKick bluetooth is only supported on linux
|
||||
- invalid pin
|
||||
vehicle:
|
||||
- "invalid plugin type: ..."
|
||||
- received status code 404
|
||||
- missing personID
|
||||
- 401 Unauthorized
|
||||
2
go.mod
2
go.mod
|
|
@ -3,7 +3,7 @@ module github.com/andig/evcc
|
|||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/andig/evcc-config v0.0.0-20200802191931-3e618540d36b
|
||||
github.com/andig/evcc-config v0.0.0-20200814164749-a3589fa3b244
|
||||
github.com/asaskevich/EventBus v0.0.0-20200428142821-4fc0642a29f3
|
||||
github.com/avast/retry-go v2.6.0+incompatible
|
||||
github.com/benbjohnson/clock v1.0.3
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -20,8 +20,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
|
|||
github.com/alvaroloes/enumer v1.1.2 h1:5khqHB33TZy1GWCO/lZwcroBFh7u+0j40T83VUbfAMY=
|
||||
github.com/alvaroloes/enumer v1.1.2/go.mod h1:FxrjvuXoDAx9isTJrv4c+T410zFi0DtXIT0m65DJ+Wo=
|
||||
github.com/andig/evcc v0.0.0-20200727161511-d58eb15f2dc9/go.mod h1:8HONEC6cC2s4k0u3QL7GIjrYOZYTOKiiXybw0FIJL0A=
|
||||
github.com/andig/evcc-config v0.0.0-20200802191931-3e618540d36b h1:IZQ3ilzJKqNTjWuGRZEhoE9HZaFRS9cRPEyuxHn5Rqc=
|
||||
github.com/andig/evcc-config v0.0.0-20200802191931-3e618540d36b/go.mod h1:N0hIjIy+5E2AR1fF7Tg2IzBlblBrnFvCCaDGAaHzbWk=
|
||||
github.com/andig/evcc-config v0.0.0-20200814164749-a3589fa3b244 h1:T1BN+JT/s49O3PsD22xep5RogK1xHBfERY+o7NljGo0=
|
||||
github.com/andig/evcc-config v0.0.0-20200814164749-a3589fa3b244/go.mod h1:N0hIjIy+5E2AR1fF7Tg2IzBlblBrnFvCCaDGAaHzbWk=
|
||||
github.com/andig/gosunspec v0.0.0-20200429133549-3cf6a82fed9c h1:AMtX56iHlNYVxMID7fe9efuVtaxgtdjyMeolg7q87IE=
|
||||
github.com/andig/gosunspec v0.0.0-20200429133549-3cf6a82fed9c/go.mod h1:YkshK8WMzYn1iXAZzHUO75gIqhMSan2ctgBVtBkRIyA=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
|
|
|
|||
|
|
@ -7,9 +7,19 @@ import (
|
|||
)
|
||||
|
||||
func TestMeters(t *testing.T) {
|
||||
acceptable := []string{
|
||||
"invalid plugin type: ...",
|
||||
"mqtt not configured",
|
||||
"NRGKick bluetooth is only supported on linux",
|
||||
"invalid pin",
|
||||
"not a SunSpec device",
|
||||
"connect: no route to host",
|
||||
"connect: connection refused",
|
||||
}
|
||||
|
||||
for _, tmpl := range test.ConfigTemplates("meter") {
|
||||
_, err := NewFromConfig(tmpl.Type, tmpl.Config)
|
||||
if err != nil && !test.Acceptable("meter", err) {
|
||||
if err != nil && !test.Acceptable(err, acceptable) {
|
||||
t.Logf("%s", tmpl.Name)
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,14 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const config = "../errors.yaml"
|
||||
|
||||
var acceptable map[string][]string
|
||||
|
||||
// Acceptable checks if a test error is configured as acceptable
|
||||
func Acceptable(class string, err error) bool {
|
||||
if len(acceptable) == 0 {
|
||||
definitions, err := ioutil.ReadFile(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := yaml.Unmarshal(definitions, &acceptable); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, msg := range acceptable[class] {
|
||||
if strings.HasPrefix(err.Error(), msg) {
|
||||
// Acceptable checks if a test error is in the list of acceptable errors
|
||||
func Acceptable(err error, acceptable []string) bool {
|
||||
for _, msg := range acceptable {
|
||||
err := strings.TrimSpace(err.Error())
|
||||
if strings.HasPrefix(err, msg) || strings.HasSuffix(err, msg) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,18 @@ package test
|
|||
|
||||
import (
|
||||
"github.com/andig/evcc-config/registry"
|
||||
_ "github.com/andig/evcc-config/templates"
|
||||
_ "github.com/andig/evcc-config/templates" // import all config templates
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type ParsedTempalte struct {
|
||||
// ConfigTemplate is a configuration template from https://github.com/andig/evcc-config
|
||||
type ConfigTemplate struct {
|
||||
registry.Template
|
||||
Config map[string]interface{}
|
||||
}
|
||||
|
||||
// ConfigTemplates returns configuration templates for giving class
|
||||
func ConfigTemplates(class string) (res []ParsedTempalte) {
|
||||
func ConfigTemplates(class string) (res []ConfigTemplate) {
|
||||
templates := registry.TemplatesByClass(class)
|
||||
|
||||
for _, tmpl := range templates {
|
||||
|
|
@ -22,7 +23,7 @@ func ConfigTemplates(class string) (res []ParsedTempalte) {
|
|||
continue
|
||||
}
|
||||
|
||||
parsed := ParsedTempalte{
|
||||
parsed := ConfigTemplate{
|
||||
Template: tmpl,
|
||||
Config: conf,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,16 @@ import (
|
|||
)
|
||||
|
||||
func TestVehicles(t *testing.T) {
|
||||
acceptable := []string{
|
||||
"invalid plugin type: ...",
|
||||
"received status code 404 (INVALID PARAMS)",
|
||||
"missing personID",
|
||||
"401 Unauthorized",
|
||||
}
|
||||
|
||||
for _, tmpl := range test.ConfigTemplates("vehicle") {
|
||||
_, err := NewFromConfig(tmpl.Type, tmpl.Config)
|
||||
if err != nil && !test.Acceptable("vehicle", err) {
|
||||
if err != nil && !test.Acceptable(err, acceptable) {
|
||||
t.Logf("%s", tmpl.Name)
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue