-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
104 lines (95 loc) · 1.91 KB
/
main_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
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestMainCheck_matches(t *testing.T) {
testcases := map[string]struct {
input string
regex []string
expected bool
}{
"simple-t": {
input: "unittest",
regex: []string{"unit", "foobar"},
expected: true,
},
"simple-f": {
input: "unittest",
regex: []string{"barfoo", "foobar"},
expected: false,
},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
actual := matches(tc.input, tc.regex)
assert.Equal(t, tc.expected, actual)
})
}
}
func TestMainAlerts_GetPerfdata(t *testing.T) {
testcases := map[string]struct {
ao AlertOverview
expected string
}{
"simple-overview": {
ao: AlertOverview{},
expected: "'alerts'=0 'alerts_high'=0 'alerts_medium'=0 'alerts_low'=0",
},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
actual := tc.ao.GetPerfdata()
assert.Equal(t, tc.expected, actual)
})
}
}
func TestMainAlerts_GetOutput(t *testing.T) {
testcases := map[string]struct {
ao AlertOverview
expected string
}{
"simple-overview": {
ao: AlertOverview{
Total: 1,
Output: []string{"test"},
},
expected: "\n## Alerts\ntest\n",
},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
actual := tc.ao.GetOutput()
assert.Equal(t, tc.expected, actual)
})
}
}
func TestMainAlerts_GetStatus(t *testing.T) {
testcases := map[string]struct {
ao AlertOverview
expected int
}{
"simple-overview": {
ao: AlertOverview{},
expected: 0,
},
"simple-warning": {
ao: AlertOverview{
Medium: 1,
},
expected: 1,
},
"simple-critical": {
ao: AlertOverview{
High: 1,
},
expected: 2,
},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
actual := tc.ao.GetStatus()
assert.Equal(t, tc.expected, actual)
})
}
}