forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contains_test.go
68 lines (60 loc) · 1.25 KB
/
contains_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
package health_test
import (
"testing"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/outputs/health"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
func TestFieldFound(t *testing.T) {
metrics := []telegraf.Metric{
testutil.MustMetric(
"cpu",
map[string]string{},
map[string]interface{}{
"time_idle": 42.0,
},
time.Now()),
}
contains := &health.Contains{
Field: "time_idle",
}
result := contains.Check(metrics)
require.True(t, result)
}
func TestFieldNotFound(t *testing.T) {
metrics := []telegraf.Metric{
testutil.MustMetric(
"cpu",
map[string]string{},
map[string]interface{}{},
time.Now()),
}
contains := &health.Contains{
Field: "time_idle",
}
result := contains.Check(metrics)
require.False(t, result)
}
func TestOneMetricWithFieldIsSuccess(t *testing.T) {
metrics := []telegraf.Metric{
testutil.MustMetric(
"cpu",
map[string]string{},
map[string]interface{}{},
time.Now()),
testutil.MustMetric(
"cpu",
map[string]string{},
map[string]interface{}{
"time_idle": 42.0,
},
time.Now()),
}
contains := &health.Contains{
Field: "time_idle",
}
result := contains.Check(metrics)
require.True(t, result)
}