forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnstat_test.go
51 lines (44 loc) · 1.3 KB
/
nstat_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
package nstat
import "testing"
func TestLoadUglyTable(t *testing.T) {
uglyStr := `IpExt: InNoRoutes InTruncatedPkts InMcastPkts InCEPkts
IpExt: 332 433718 0 2660494435`
parsed := map[string]interface{}{
"IpExtInNoRoutes": int64(332),
"IpExtInTruncatedPkts": int64(433718),
"IpExtInMcastPkts": int64(0),
"IpExtInCEPkts": int64(2660494435),
}
n := Nstat{DumpZeros: true}
got := n.loadUglyTable([]byte(uglyStr))
if len(got) == 0 {
t.Fatalf("want %+v, got %+v", parsed, got)
}
for key := range parsed {
if parsed[key].(int64) != got[key].(int64) {
t.Fatalf("want %+v, got %+v", parsed[key], got[key])
}
}
}
func TestLoadGoodTable(t *testing.T) {
goodStr := `Ip6InReceives 11707
Ip6InTooBigErrors 0
Ip6InDelivers 62
Ip6InMcastOctets 1242966`
parsed := map[string]interface{}{
"Ip6InReceives": int64(11707),
"Ip6InTooBigErrors": int64(0),
"Ip6InDelivers": int64(62),
"Ip6InMcastOctets": int64(1242966),
}
n := Nstat{DumpZeros: true}
got := n.loadGoodTable([]byte(goodStr))
if len(got) == 0 {
t.Fatalf("want %+v, got %+v", parsed, got)
}
for key := range parsed {
if parsed[key].(int64) != got[key].(int64) {
t.Fatalf("want %+v, got %+v", parsed[key], got[key])
}
}
}