-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollector_test.go
90 lines (78 loc) · 2.04 KB
/
collector_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
package main
import (
"testing"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
configondatv1 "github.com/ondat/metrics-exporter/api/config.storageos.com/v1"
)
func TestGetEnabledMetricsCollectors(t *testing.T) {
tests := []struct {
name string
disable []configondatv1.MetricsExporterCollector
expectedEnabled []string
}{
{
name: "all enabled",
disable: nil,
expectedEnabled: []string{
"diskstats",
"filesystem",
},
},
{
name: "disable filesystem",
disable: []configondatv1.MetricsExporterCollector{configondatv1.MetricsExporterCollectorFileSystem},
expectedEnabled: []string{
"diskstats",
},
},
{
name: "disable diskstats",
disable: []configondatv1.MetricsExporterCollector{configondatv1.MetricsExporterCollectorDiskStats},
expectedEnabled: []string{
"filesystem",
},
},
{
name: "disable both",
disable: []configondatv1.MetricsExporterCollector{
configondatv1.MetricsExporterCollectorFileSystem,
configondatv1.MetricsExporterCollectorDiskStats,
},
expectedEnabled: []string{},
},
{
name: "disable both - reversed",
disable: []configondatv1.MetricsExporterCollector{
configondatv1.MetricsExporterCollectorDiskStats,
configondatv1.MetricsExporterCollectorFileSystem,
},
expectedEnabled: []string{},
},
{
name: "ignore bad value",
disable: []configondatv1.MetricsExporterCollector{
configondatv1.MetricsExporterCollector("bad"),
configondatv1.MetricsExporterCollectorFileSystem,
},
expectedEnabled: []string{
"diskstats",
},
},
}
for _, tt := range tests {
var tt = tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
loggerConfig := zap.NewProductionConfig()
logger, _ := loggerConfig.Build()
log := logger.Sugar()
collectors := GetEnabledMetricsCollectors(log, tt.disable)
names := make([]string, 0, len(collectors))
for _, c := range collectors {
names = append(names, c.Name())
}
require.ElementsMatch(t, tt.expectedEnabled, names)
})
}
}