-
Notifications
You must be signed in to change notification settings - Fork 1
/
sigmund_test.go
57 lines (51 loc) · 1.38 KB
/
sigmund_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
package sigmund
import (
"errors"
"testing"
)
type identifyMetrics struct {
metric string
expected error
}
var identifyPositiveMetrics = []identifyMetrics{
identifyMetrics{
metric: "cpu",
expected: nil,
},
identifyMetrics{
metric: "memory",
expected: nil,
},
}
var identifyNegativeMetrics = []identifyMetrics{
identifyMetrics{
metric: "CPU",
expected: errors.New("CPU is an invalid parameter. Please provide either 'memory' or 'cpu' keys"),
},
identifyMetrics{
metric: "SuperMan",
expected: errors.New("CPU is an invalid parameter. Please provide either 'memory' or 'cpu' keys"),
},
identifyMetrics{
metric: "",
expected: errors.New(" is an invalid parameter. Please provide either 'memory' or 'cpu' keys"),
},
}
// Positive Tests for Metric Identifier function
func TestPositiveIdentifyMetric(t *testing.T) {
for _, im := range identifyPositiveMetrics {
result, err := identifyMetric(im.metric)
if err != nil {
t.Errorf("Invalid parameter! Expected: %s, got: %s", im.metric, result)
}
}
}
// Negative Tests for Metric Identifier function
func TestNegativeIdentifyMetric(t *testing.T) {
for _, im := range identifyNegativeMetrics {
_, err := identifyMetric(im.metric)
if err == nil {
t.Errorf("Invalid error message! Expected: \"%s is an invalid parameter. Please provide either 'memory' or 'cpu' keys\", got: %v", im.metric, err)
}
}
}