func TestRegularConfig(t *testing.T) { a := assert.New(t) r := require.New(t) cfg, err := ReadConfig(bytes.NewReader(defaultConfig)) r.Nil(err) a.Equal(5, len(cfg.Checks)) a.Equal(1, len(cfg.Publishers)) }
func TestPublisherInit(t *testing.T) { a := assert.New(t) r := require.New(t) runner, err := NewRunnerFromFile("testdata/config.yml") r.Nil(err) r.Equal(1, len(runner.publishers)) expectType := reflect.TypeOf(&MemoryPublisher{}) realType := reflect.TypeOf(runner.publishers["memory"]) a.Equal(expectType, realType) }
func TestChecks(t *testing.T) { a := assert.New(t) r := require.New(t) _, err := ReadConfig(strings.NewReader("checks: { valid: {command: foo} }")) a.Nil(err) _, err = ReadConfig(strings.NewReader("checks: { invalid: {} }")) a.NotNil(err) if errt, ok := err.(Error); !ok || errt.Code != ErrInvalidConfig { t.Error("Expected error to be ErrInvalidConfig") } cfg, err := ReadConfig(bytes.NewReader(defaultConfig)) r.Nil(err) check, ok := cfg.Checks["Dummy OK"] if !ok { t.Fatal("Expected 'Dummy OK' check not found") } a.Equal("Dummy OK", check.Name) a.Equal("/usr/lib/nagios/plugins/check_dummy 0", check.Command) a.Equal([]string{"/usr/lib/nagios/plugins/check_dummy", "0"}, check.Args) a.Equal(60, check.Interval) a.Equal(60, check.Retry) a.Equal(10, check.Timeout) check, ok = cfg.Checks["Custom"] if !ok { t.Fatal("Expected 'Dummy OK' check not found") } a.Equal("Custom check", check.Name) a.Equal(10, check.Interval) a.Equal(3, check.Retry) a.Equal(3, check.Timeout) }