Debian Codegraph @

thresholds_test.go

raw
1 package monitoringplugin
2
3 import (
4 "github.com/stretchr/testify/assert"
5 "testing"
6 )
7
8 func TestValidateThresholds(t *testing.T) {
9 th1 := Thresholds{
10 WarningMin: 5,
11 WarningMax: 10,
12 CriticalMin: 3,
13 CriticalMax: 12,
14 }
15 assert.NoError(t, th1.Validate())
16
17 th2 := Thresholds{
18 WarningMin: 0,
19 WarningMax: 10,
20 CriticalMin: 0,
21 CriticalMax: 12,
22 }
23 assert.NoError(t, th2.Validate())
24
25 th3 := Thresholds{}
26 assert.NoError(t, th3.Validate())
27
28 th4 := Thresholds{
29 WarningMax: 3,
30 }
31 assert.NoError(t, th4.Validate())
32
33 th5 := Thresholds{
34 WarningMin: 2,
35 WarningMax: 1,
36 }
37 assert.Error(t, th5.Validate())
38
39 th6 := Thresholds{
40 CriticalMin: 2,
41 CriticalMax: 1,
42 }
43 assert.Error(t, th6.Validate())
44
45 th7 := Thresholds{
46 WarningMin: 1,
47 CriticalMin: 2,
48 }
49 assert.Error(t, th7.Validate())
50
51 th8 := Thresholds{
52 WarningMax: 2,
53 CriticalMax: 1,
54 }
55 assert.Error(t, th8.Validate())
56 }
57
58 func TestCheckThresholds(t *testing.T) {
59 th1 := Thresholds{
60 WarningMin: 5,
61 WarningMax: 10,
62 CriticalMin: 3,
63 CriticalMax: 12,
64 }
65
66 res, err := th1.CheckValue(6)
67 assert.NoError(t, err)
68 assert.Equal(t, OK, res)
69
70 res, err = th1.CheckValue(5)
71 assert.NoError(t, err)
72 assert.Equal(t, OK, res)
73
74 res, err = th1.CheckValue(10)
75 assert.NoError(t, err)
76 assert.Equal(t, OK, res)
77
78 res, err = th1.CheckValue(4)
79 assert.NoError(t, err)
80 assert.Equal(t, WARNING, res)
81
82 res, err = th1.CheckValue(11)
83 assert.NoError(t, err)
84 assert.Equal(t, WARNING, res)
85
86 res, err = th1.CheckValue(3)
87 assert.NoError(t, err)
88 assert.Equal(t, WARNING, res)
89
90 res, err = th1.CheckValue(12)
91 assert.NoError(t, err)
92 assert.Equal(t, WARNING, res)
93
94 res, err = th1.CheckValue(2)
95 assert.NoError(t, err)
96 assert.Equal(t, CRITICAL, res)
97
98 res, err = th1.CheckValue(13)
99 assert.NoError(t, err)
100 assert.Equal(t, CRITICAL, res)
101
102 th2 := Thresholds{
103 WarningMin: 5,
104 WarningMax: 10,
105 CriticalMin: 5,
106 CriticalMax: 12,
107 }
108
109 res, err = th2.CheckValue(4)
110 assert.NoError(t, err)
111 assert.Equal(t, CRITICAL, res)
112 }