-
Notifications
You must be signed in to change notification settings - Fork 0
/
muninplugin_test.go
183 lines (166 loc) · 4.16 KB
/
muninplugin_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package muninplugin
import (
"strings"
"testing"
)
func TestNewPlugin(t *testing.T) {
p := NewPlugin()
switch interface{}(p).(type) {
case *Plugin:
t.Logf("NewPlugin() created a *Plugin: %v\n", p)
default:
t.Fatalf("NewPlugin() did not create a *Plugin")
}
}
func TestNewMetric(t *testing.T) {
m := newMetric()
switch interface{}(m).(type) {
case *Metric:
t.Logf("NewMetric() created a *Metric: %v\n", m)
default:
t.Fatalf("NewMetric() did not create a *Metric")
}
}
func TestNewMetrics(t *testing.T) {
m := newMetrics()
switch interface{}(m).(type) {
case Metrics:
t.Logf("NewMetrics() created a Metrics: %v\n", m)
default:
t.Fatalf("NewMetrics() did not create a Metrics")
}
}
func TestNewPluginDefaults(t *testing.T) {
p := NewPlugin()
if p.Graph == true {
t.Log("Plugin Graph member correctly set to true by default.")
} else {
t.Fatalf("Plugin Graph member not set true by default.")
}
if p.GraphScale == false {
t.Log("Plugin GraphScale correctly set to false by default.")
} else {
t.Fatalf("Plugin GraphScale not set false by default.")
}
if p.Update == true {
t.Log("Plugin Update correctly set to true by default.")
} else {
t.Fatalf("Plugin Update not set true by default.")
}
}
func TestPluginConfig(t *testing.T) {
expectedDirectives := map[string]bool{
"graph yes": false,
"graph_category Filesystem": false,
"graph_height 600": false,
"graph_title Test Title": false,
"graph_width 800": false,
"graph_vlabel Vertical": false,
}
p := NewPlugin()
p.GraphTitle = "Test Title"
p.GraphHeight = 600
p.GraphWidth = 800
p.GraphVLabel = "Vertical"
p.GraphCategory = "Filesystem"
foundDirectives := strings.Split(p.Config(), "\n")
t.Log(p.Config())
for _, d := range foundDirectives {
if len(d) > 0 {
if _, ok := expectedDirectives[d]; ok {
expectedDirectives[d] = true
} else {
t.Logf("Could not find: %s in Plugin Config output\n", d)
}
}
}
for dir, fnd := range expectedDirectives {
if fnd == true {
t.Logf("Found expected: %s\n", dir)
} else {
t.Fatalf("Not found: %s\n", dir)
}
}
}
func TestMetricsConfig(t *testing.T) {
expectedDirectives := map[string]bool{
"test.label test": false,
"test.critical 190.00": false,
"test.graph yes": false,
"test.max 200": false,
"test.min 0": false,
"test.warning 120": false,
"test.info extra": false,
}
m := newMetrics()
m["test"] = newMetric()
m["test"].Value = 100
m["test"].Min = 0
m["test"].Max = 200
m["test"].Critical = 190.00
m["test"].Warning = 120
m["test"].Info = "extra"
t.Log(m.Config())
foundDirectives := strings.Split(m.Config(), "\n")
for _, d := range foundDirectives {
if len(d) > 0 {
if _, ok := expectedDirectives[d]; ok {
expectedDirectives[d] = true
} else {
t.Fatalf("Could not find: %s in Metrics output\n", d)
}
}
}
for dir, fnd := range expectedDirectives {
if fnd == true {
t.Logf("Found expected: %s\n", dir)
} else {
t.Fatalf("Not Found: %s\n", dir)
}
}
}
func TestMetricsValues(t *testing.T) {
expectedDirectives := map[string]bool{
"float.value 3.14": true,
"int.value 3": true,
"nonumber.value U": true,
}
m := newMetrics()
m["float"] = newMetric()
m["float"].Value = 3.14
m["int"] = newMetric()
m["int"].Value = 3
m["nonumber"] = newMetric()
m["nonumber"].Value = "this is not a number"
foundDirectives := strings.Split(m.Values(), "\n")
for _, d := range foundDirectives {
if len(d) > 0 {
if _, ok := expectedDirectives[d]; ok {
expectedDirectives[d] = true
} else {
t.Fatalf("Could not find: %s in Metrics output\n", d)
}
}
}
for dir, fnd := range expectedDirectives {
if fnd == true {
t.Logf("Found expected: %s\n", dir)
} else {
t.Fatalf("Not Found: %s\n", dir)
}
}
}
func TestBuildGraphOrderSlice(t *testing.T) {
p := NewPlugin()
p.MakeMetric("first")
p.MakeMetric("second")
p.MakeMetric("third")
p.MakeMetric("fourth")
p.MakeMetric("fifth")
t.Logf(p.Config())
if p.graphOrder[0] == "first" && p.graphOrder[4] == "fifth" {
t.Logf("Correct graphOrder %v\n", p.graphOrder)
} else {
t.Fatalf("Incorrect graphOrder %v\n", p.graphOrder)
}
}