Repository navigation
Expand file tree
/
Copy pathmain_test.go
More file actions
113 lines (103 loc) · 2.14 KB
/
Copy pathmain_test.go
File metadata and controls
113 lines (103 loc) · 2.14 KB
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
113
package main
import (
"testing"
"github.com/NETWAYS/go-check"
)
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)
if tc.expected != actual {
t.Fatalf("expected %v, got %v", 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()
if tc.expected != actual {
t.Fatalf("expected %v, got %v", 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()
if tc.expected != actual {
t.Fatalf("expected %v, got %v", tc.expected, actual)
}
})
}
}
func TestMainAlerts_GetStatus(t *testing.T) {
testcases := map[string]struct {
ao AlertOverview
expected check.Status
}{
"simple-overview": {
ao: AlertOverview{},
expected: check.OK,
},
"simple-warning": {
ao: AlertOverview{
Medium: 1,
},
expected: check.Warning,
},
"simple-critical": {
ao: AlertOverview{
High: 1,
},
expected: check.Critical,
},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
actual := tc.ao.GetStatus()
if tc.expected != actual {
t.Fatalf("expected %v, got %v", tc.expected, actual)
}
})
}
}