Update linting and a test case
This commit is contained in:
+33
-11
@@ -33,16 +33,10 @@ func TestCheckMonitors(t *testing.T) {
|
||||
Command: CommandOrShell{Command: []string{"false"}},
|
||||
AlertAfter: 1,
|
||||
},
|
||||
&Monitor{
|
||||
Name: "Failure",
|
||||
Command: CommandOrShell{Command: []string{"false"}},
|
||||
AlertDown: []string{"unknown"},
|
||||
AlertAfter: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
expectErr: false,
|
||||
name: "Monitor failure, no and unknown alerts",
|
||||
name: "Monitor failure, no alerts",
|
||||
},
|
||||
{
|
||||
config: Config{
|
||||
@@ -52,6 +46,28 @@ func TestCheckMonitors(t *testing.T) {
|
||||
Command: CommandOrShell{Command: []string{"ls"}},
|
||||
alertCount: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
expectErr: false,
|
||||
name: "Monitor recovery, no alerts",
|
||||
},
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
Name: "Failure",
|
||||
Command: CommandOrShell{Command: []string{"false"}},
|
||||
AlertDown: []string{"unknown"},
|
||||
AlertAfter: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
expectErr: true,
|
||||
name: "Monitor failure, unknown alerts",
|
||||
},
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
Name: "Success",
|
||||
Command: CommandOrShell{Command: []string{"true"}},
|
||||
@@ -60,8 +76,8 @@ func TestCheckMonitors(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectErr: false,
|
||||
name: "Monitor recovery, no alerts",
|
||||
expectErr: true,
|
||||
name: "Monitor recovery, unknown alerts",
|
||||
},
|
||||
{
|
||||
config: Config{
|
||||
@@ -105,10 +121,16 @@ func TestCheckMonitors(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c.config.Init()
|
||||
err := checkMonitors(&c.config)
|
||||
err := c.config.Init()
|
||||
if err != nil {
|
||||
t.Errorf("checkMonitors(%s): unexpected error reading config: %v", c.name, err)
|
||||
}
|
||||
|
||||
err = checkMonitors(&c.config)
|
||||
if err == nil && c.expectErr {
|
||||
t.Errorf("checkMonitors(%s): Expected panic, the code did not panic", c.name)
|
||||
} else if err != nil && !c.expectErr {
|
||||
t.Errorf("checkMonitors(%s): Did not expect an error, but we got one anyway: %v", c.name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user