-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathmetric_test.go
106 lines (102 loc) · 1.88 KB
/
metric_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
package testutil
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/metric"
)
func TestRequireMetricEqual(t *testing.T) {
tests := []struct {
name string
got telegraf.Metric
want telegraf.Metric
}{
{
name: "equal metrics should be equal",
got: func() telegraf.Metric {
m, _ := metric.New(
"test",
map[string]string{
"t1": "v1",
"t2": "v2",
},
map[string]interface{}{
"f1": 1,
"f2": 3.14,
"f3": "v3",
},
time.Unix(0, 0),
)
return m
}(),
want: func() telegraf.Metric {
m, _ := metric.New(
"test",
map[string]string{
"t1": "v1",
"t2": "v2",
},
map[string]interface{}{
"f1": int64(1),
"f2": 3.14,
"f3": "v3",
},
time.Unix(0, 0),
)
return m
}(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
RequireMetricEqual(t, tt.want, tt.got)
})
}
}
func TestRequireMetricsEqual(t *testing.T) {
tests := []struct {
name string
got []telegraf.Metric
want []telegraf.Metric
opts []cmp.Option
}{
{
name: "sort metrics option sorts by name",
got: []telegraf.Metric{
MustMetric(
"cpu",
map[string]string{},
map[string]interface{}{},
time.Unix(0, 0),
),
MustMetric(
"net",
map[string]string{},
map[string]interface{}{},
time.Unix(0, 0),
),
},
want: []telegraf.Metric{
MustMetric(
"net",
map[string]string{},
map[string]interface{}{},
time.Unix(0, 0),
),
MustMetric(
"cpu",
map[string]string{},
map[string]interface{}{},
time.Unix(0, 0),
),
},
opts: []cmp.Option{SortMetrics()},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
RequireMetricsEqual(t, tt.want, tt.got, tt.opts...)
})
}
}