2019-10-04 01:16:03 +00:00
|
|
|
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"},
|
2019-10-07 17:48:19 +00:00
|
|
|
{"./test/invalid-config-unknown-alert.yml", true, "Invalid config unknown alert"},
|
2019-10-04 01:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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("-----")
|
|
|
|
}
|
|
|
|
}
|