-
Notifications
You must be signed in to change notification settings - Fork 1
/
thresholds_test.go
112 lines (91 loc) · 1.95 KB
/
thresholds_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package monitoringplugin
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestValidateThresholds(t *testing.T) {
th1 := Thresholds{
WarningMin: 5,
WarningMax: 10,
CriticalMin: 3,
CriticalMax: 12,
}
assert.NoError(t, th1.Validate())
th2 := Thresholds{
WarningMin: 0,
WarningMax: 10,
CriticalMin: 0,
CriticalMax: 12,
}
assert.NoError(t, th2.Validate())
th3 := Thresholds{}
assert.NoError(t, th3.Validate())
th4 := Thresholds{
WarningMax: 3,
}
assert.NoError(t, th4.Validate())
th5 := Thresholds{
WarningMin: 2,
WarningMax: 1,
}
assert.Error(t, th5.Validate())
th6 := Thresholds{
CriticalMin: 2,
CriticalMax: 1,
}
assert.Error(t, th6.Validate())
th7 := Thresholds{
WarningMin: 1,
CriticalMin: 2,
}
assert.Error(t, th7.Validate())
th8 := Thresholds{
WarningMax: 2,
CriticalMax: 1,
}
assert.Error(t, th8.Validate())
}
func TestCheckThresholds(t *testing.T) {
th1 := Thresholds{
WarningMin: 5,
WarningMax: 10,
CriticalMin: 3,
CriticalMax: 12,
}
res, err := th1.CheckValue(6)
assert.NoError(t, err)
assert.Equal(t, OK, res)
res, err = th1.CheckValue(5)
assert.NoError(t, err)
assert.Equal(t, OK, res)
res, err = th1.CheckValue(10)
assert.NoError(t, err)
assert.Equal(t, OK, res)
res, err = th1.CheckValue(4)
assert.NoError(t, err)
assert.Equal(t, WARNING, res)
res, err = th1.CheckValue(11)
assert.NoError(t, err)
assert.Equal(t, WARNING, res)
res, err = th1.CheckValue(3)
assert.NoError(t, err)
assert.Equal(t, WARNING, res)
res, err = th1.CheckValue(12)
assert.NoError(t, err)
assert.Equal(t, WARNING, res)
res, err = th1.CheckValue(2)
assert.NoError(t, err)
assert.Equal(t, CRITICAL, res)
res, err = th1.CheckValue(13)
assert.NoError(t, err)
assert.Equal(t, CRITICAL, res)
th2 := Thresholds{
WarningMin: 5,
WarningMax: 10,
CriticalMin: 5,
CriticalMax: 12,
}
res, err = th2.CheckValue(4)
assert.NoError(t, err)
assert.Equal(t, CRITICAL, res)
}