A simple monitoring solution written in Go (work in progress)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

package config
import (
"strings"
"testing"
)
// Is the absence of hosts and groups detected?
func TestNoHosts(t *testing.T) {
_, err := ReadConfig("testdata/no_hosts.yaml", 0)
if err != ERR_NO_GROUPHOST {
t.Errorf("missing hosts/groups not detected: %s", err.Error())
}
}
// Are duplicate host names detected?
func TestDupHosts(t *testing.T) {
_, err := ReadConfig("testdata/dup_hosts.yaml", 0)
if err == nil || !strings.HasPrefix(err.Error(), "duplicate host") {
t.Errorf("duplicate hosts not detected: %s", err.Error())
}
}
// Are duplicate host names inside groups detected?
func TestDupGroupHosts(t *testing.T) {
_, err := ReadConfig("testdata/dup_group_hosts.yaml", 0)
if err == nil || !strings.HasPrefix(err.Error(), "duplicate host") {
t.Errorf("duplicate hosts not detected: %s", err.Error())
}
}
// Test if api_key and api_key_file are both defined
func TestDupAPI(t *testing.T) {
_, err := ReadConfig("testdata/dup_api_key.yaml", 0)
if err != ERR_DUP_API {
t.Errorf("missing api key/api key file not detected: %s", err.Error())
}
}
// Are undefined api key / key files detected?
func TestUndefinedAPI(t *testing.T) {
_, err := ReadConfig("testdata/no_api_key.yaml", 0)
if err != ERR_NO_API {
t.Errorf("undefined api key/api key file not detected: %s", err.Error())
}
}
// Are missing api key files detected?
func TestMissingAPIKey(t *testing.T) {
_, err := ReadConfig("testdata/missing_api_keyfile.yaml", 0)
if err != ERR_MISSING_KEYFILE {
t.Errorf("missing api key file not detected: %s", err.Error())
}
}
// Test if referenced alarm exists (and is a valid type)
// Test if referenced check exists (and is a valid type)