forked from zoni/nagios-check-runner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchecker_test.go
44 lines (38 loc) · 1021 Bytes
/
checker_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package nca
import (
"bytes"
"gopkg.in/stretchr/testify.v1/assert"
"testing"
)
func TestRunCheck(t *testing.T) {
a := assert.New(t)
check := Check{
Name: "Dummy",
Command: "",
Args: []string{"testdata/check_dummy", "0", "OK"},
Interval: 1,
Retry: 1,
Timeout: 5,
}
result := runCheck(check)
a.Equal(StateOk, result.Returncode)
check.Args = []string{"testdata/check_dummy", "2", "CRITICAL!"}
result = runCheck(check)
a.Equal(StateCritical, result.Returncode)
a.Equal(
bytes.TrimSpace([]byte("CRITICAL!")),
bytes.TrimSpace(result.Output),
)
check.Args = []string{"/no/such/file/or/directory"}
result = runCheck(check)
a.Equal(StateCritical, result.Returncode)
// Note: Leave this test last or set timeout back
check.Args = []string{"/bin/sleep", "2"}
check.Timeout = 1
result = runCheck(check)
a.Equal(StateCritical, result.Returncode)
a.Equal(
bytes.TrimSpace([]byte("Process /bin/sleep was killed after 1 second timeout")),
bytes.TrimSpace(result.Output),
)
}