88 lines
1.6 KiB
Go
88 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/andig/evcc/provider"
|
|
"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("config: failed parsing config file %s: %v", cfgFile, err)
|
|
}
|
|
|
|
// setup mqtt
|
|
if viper.Get("mqtt") != nil {
|
|
provider.MQTT = provider.NewMqttClient(conf.Mqtt.Broker, conf.Mqtt.User, conf.Mqtt.Password, clientID(), 1)
|
|
}
|
|
|
|
// check config is valid
|
|
loadConfig(conf, nil)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|