telegraf/plugins/outputs/health/contains_test.go

69 lines
1.2 KiB
Go
Raw Normal View History

2019-05-30 01:31:06 +00:00
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)
}