minitor-go/config_test.go
Ian Fijolek 351216c3a7 Add more config validation
Validates that all alerts are actually found in the alert list
2019-10-07 10:48:19 -07:00

32 lines
835 B
Go

package main
import (
"log"
"testing"
)
func TestLoadConfig(t *testing.T) {
cases := []struct {
configPath string
expectErr bool
name string
}{
{"./test/valid-config.yml", false, "Valid config file"},
{"./test/does-not-exist", true, "Invalid config path"},
{"./test/invalid-config-type.yml", true, "Invalid config type for key"},
{"./test/invalid-config-missing-alerts.yml", true, "Invalid config missing alerts"},
{"./test/invalid-config-unknown-alert.yml", true, "Invalid config unknown alert"},
}
for _, c := range cases {
log.Printf("Testing case %s", c.name)
_, err := LoadConfig(c.configPath)
hasErr := (err != nil)
if hasErr != c.expectErr {
t.Errorf("LoadConfig(%v), expected=%v actual=%v", c.name, "Err", err)
log.Printf("Case failed: %s", c.name)
}
log.Println("-----")
}
}