-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
72 lines (63 loc) · 1.47 KB
/
config_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
package main
import (
"strings"
"testing"
"github.com/NETWAYS/check_akcp_sensorprobeXplus/internal/akcp"
"github.com/NETWAYS/check_akcp_sensorprobeXplus/internal/akcp/sensorProbePlus"
"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/result"
)
func TestSensorStatus(t *testing.T) {
testcases := map[string]struct {
sensor akcp.SensorDetails
expected string
}{
"normal": {
sensor: akcp.SensorDetails{
Unit: "C",
Status: akcp.Normal,
},
expected: "states: ok=1\n\\_ [OK] : 0.0",
},
"HighWarning": {
sensor: akcp.SensorDetails{
Unit: "Foo",
Status: akcp.HighWarning,
},
expected: "[WARNING] : 0.0Foo",
},
"LowCritical": {
sensor: akcp.SensorDetails{
SensorType: sensorProbePlus.Motion,
Unit: "Bar",
Value: 1,
Warning: akcp.MayThreshold{
Present: true,
Val: check.Threshold{Lower: 10},
},
Status: akcp.LowCritical,
},
expected: "[CRITICAL] : Bar",
},
"Error": {
sensor: akcp.SensorDetails{
Unit: "Error",
Status: akcp.SensorError,
},
expected: "[CRITICAL] ERROR!",
},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
overall := &result.Overall{}
err := mapSensorStatus(tc.sensor, overall)
if err != nil {
t.Error("Expected no error, got %w", err)
}
actual := overall.GetOutput()
if !strings.Contains(actual, tc.expected) {
t.Error("\nActual: ", actual, "\nExpected: ", tc.expected)
}
})
}
}