-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcheckers_test.go
57 lines (52 loc) · 1.27 KB
/
checkers_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
45
46
47
48
49
50
51
52
53
54
55
56
57
package checkers
import "testing"
func TestCheck(t *testing.T) {
tests := []struct {
name string
check func(s string) *Checker
msg string
status Status
s string
}{
{"ok", Ok, "OK!", OK, " OK: OK!"},
{"warn", Warning, "warn!", WARNING, " WARNING: warn!"},
{"crit", Critical, "crit!", CRITICAL, " CRITICAL: crit!"},
{"unknown", Unknown, "unknown!", UNKNOWN, " UNKNOWN: unknown!"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := tt.check(tt.msg)
if c.Status != tt.status {
t.Errorf("Status should be %v but got %v", c.Status, tt.status)
}
if c.Message != tt.msg {
t.Errorf("Message should be %s but got %s", c.Message, tt.msg)
}
if s := c.String(); s != tt.s {
t.Errorf("String() should be %q but got %q", tt.s, s)
}
})
}
}
func TestName(t *testing.T) {
ckr := Ok("OK!")
ckr.Name = "someChecker"
if ckr.String() != "someChecker OK: OK!" {
t.Errorf("ckr.Status should be 'someChecker OK OK!' but:%v\n", ckr)
}
}
func TestExit(t *testing.T) {
var exitCode int
oexit := exit
exit = func(code int) {
exitCode = code
}
t.Cleanup(func() {
exit = oexit
})
c := Critical("crit!")
c.Exit()
if exitCode != int(CRITICAL) {
t.Errorf("Exit should exit with %d but got %d", CRITICAL, exitCode)
}
}