forked from olorin/nagiosplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_test.go
51 lines (45 loc) · 1.58 KB
/
check_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
package nagiosplugin
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
)
func TestCheck(t *testing.T) {
rand.Seed(time.Now().UTC().UnixNano())
c := NewCheck()
expected := "CRITICAL: 200000 terrifying space monkeys in the engineroom | space_monkeys=200000c;10000;100000;0;4294967296"
nSpaceMonkeys := float64(200000)
maxSpaceMonkeys := float64(1 << 32)
c.AddPerfDatum("space_monkeys", "c", nSpaceMonkeys, 0, maxSpaceMonkeys, 10000, 100000)
c.AddResult(CRITICAL, fmt.Sprintf("%v terrifying space monkeys in the engineroom", nSpaceMonkeys))
// Check a WARNING can't override a CRITICAL
c.AddResult(WARNING, fmt.Sprintf("%v slightly annoying space monkeys in the engineroom", nSpaceMonkeys))
result := c.String()
if expected != result {
t.Errorf("Expected check output %v, got check output %v", expected, result)
}
}
func TestDefaultStatusPolicy(t *testing.T) {
c := NewCheck()
c.AddResult(WARNING, "Isolated-frame flux emission outside threshold")
c.AddResult(UNKNOWN, "No response from betaform amplifier")
expected := "UNKNOWN"
actual := strings.SplitN(c.String(), ":", 2)[0]
if actual != expected {
t.Errorf("Expected %v status, got %v", expected, actual)
}
}
func TestOUWCStatusPolicy(t *testing.T) {
c := NewCheckWithOptions(CheckOptions{
StatusPolicy: NewOUWCStatusPolicy(),
})
c.AddResult(WARNING, "Isolated-frame flux emission outside threshold")
c.AddResult(UNKNOWN, "No response from betaform amplifier")
expected := "WARNING"
actual := strings.SplitN(c.String(), ":", 2)[0]
if actual != expected {
t.Errorf("Expected %v status, got %v", expected, actual)
}
}