forked from mackerelio/mackerel-agent
/
interface_test.go
52 lines (44 loc) · 1.05 KB
/
interface_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
// +build !windows
package metrics
import (
"runtime"
"strings"
"testing"
"time"
)
func TestInterfaceGenerator(t *testing.T) {
g := &InterfaceGenerator{1 * time.Second}
values, err := g.Generate()
if err != nil {
t.Errorf("error should be nil but got: %s", err)
}
metrics := []string{"rxBytes", "txBytes"}
name := "eth0"
if runtime.GOOS != "linux" {
name = "en0"
}
for _, metric := range metrics {
metricName := "interface." + name + "." + metric + ".delta"
if _, ok := values[metricName]; !ok {
t.Errorf("Value for %s should be collected", metricName)
}
}
name = "lo"
if runtime.GOOS != "linux" {
name = "lo0"
}
for _, metric := range metrics {
metricName := "interface." + name + "." + metric + ".delta"
if _, ok := values[metricName]; ok {
t.Errorf("Value for %s should NOT be collected", metricName)
}
}
if runtime.GOOS == "linux" {
for k := range values {
if strings.HasPrefix(k, "interface.veth") {
t.Errorf("Value for %s should NOT be collected", k)
}
}
}
t.Logf("interface metrics: %+v", values)
}