forked from Griesbacher/check_x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerformanceData_test.go
76 lines (72 loc) · 2.39 KB
/
PerformanceData_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
package check_x
import (
"reflect"
"testing"
)
var perfdataToString = []struct {
f func() PerformanceData
expected string
}{
{func() PerformanceData {
return *NewPerformanceDataString("a", "1")
}, "'a'=1;;;;"},
{func() PerformanceData {
warn, _ := NewThreshold("10:")
return NewPerformanceDataString("a", "2").Warn(warn)
}, "'a'=2;10:;;;"},
{func() PerformanceData {
warn, _ := NewThreshold("10:")
crit, _ := NewThreshold("@10:20")
return NewPerformanceDataString("a", "3").Warn(warn).Crit(crit)
}, "'a'=3;10:;@10:20;;"},
{func() PerformanceData {
warn, _ := NewThreshold("10:")
crit, _ := NewThreshold("@10:20")
return NewPerformanceDataString("a", "3").Warn(warn).Crit(crit).Min(0)
}, "'a'=3;10:;@10:20;0;"},
{func() PerformanceData {
warn, _ := NewThreshold("10:")
crit, _ := NewThreshold("@10:20")
return NewPerformanceDataString("a", "4").Warn(warn).Crit(crit).Min(0).Max(100)
}, "'a'=4;10:;@10:20;0;100"},
{func() PerformanceData {
warn, _ := NewThreshold("10:")
crit, _ := NewThreshold("@10:20")
return NewPerformanceDataString("a", "5").Warn(warn).Crit(crit).Min(0).Max(100).Unit("C")
}, "'a'=5C;10:;@10:20;0;100"},
{func() PerformanceData {
warn, _ := NewThreshold("10:")
crit, _ := NewThreshold("@10:20")
return NewPerformanceData("a", 6).Warn(warn).Crit(crit).Min(0).Max(100).Unit("C")
}, "'a'=6C;10:;@10:20;0;100"},
{func() PerformanceData {
warn, _ := NewThreshold("")
crit, _ := NewThreshold("@10:20")
return NewPerformanceData("a", 6).Warn(warn).Crit(crit).Min(0).Max(100).Unit("C")
}, "'a'=6C;;@10:20;0;100"},
{func() PerformanceData {
crit, _ := NewThreshold("@10:20")
return NewPerformanceData("a", 6).Warn(nil).Crit(crit).Min(0).Max(100).Unit("C")
}, "'a'=6C;;@10:20;0;100"},
}
func TestPerformanceData_toString(t *testing.T) {
for i, data := range perfdataToString {
result := data.f()
resultString := result.toString()
if resultString != data.expected {
t.Errorf("%d - Expected: %s, got: %s", i, data.expected, resultString)
}
if !reflect.DeepEqual(p[i], result) {
t.Errorf("%d - Expected: %s, got: %s", i, p[i], result)
}
}
}
func TestPrintPerformanceData(t *testing.T) {
p = []PerformanceData{}
NewPerformanceDataString("a", "1")
NewPerformanceDataString("b", "2")
expected := "'a'=1;;;;" + " " + "'b'=2;;;; "
if expected != PrintPerformanceData() {
t.Errorf("Expected: %s, got: %s", expected, PrintPerformanceData())
}
}