telegraf/plugins/outputs/prometheus_client/prometheus_client_test.go

88 lines
1.8 KiB
Go
Raw Normal View History

package prometheus_client
import (
"testing"
2016-01-07 17:52:46 +00:00
"github.com/stretchr/testify/require"
"github.com/influxdata/telegraf"
2016-01-20 18:57:35 +00:00
"github.com/influxdata/telegraf/plugins/inputs/prometheus"
"github.com/influxdata/telegraf/testutil"
)
var pTesting *PrometheusClient
func TestPrometheusWritePointEmptyTag(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
pTesting = &PrometheusClient{Listen: "localhost:9127"}
pTesting.Start()
defer pTesting.Stop()
p := &prometheus.Prometheus{
Urls: []string{"http://localhost:9127/metrics"},
}
tags := make(map[string]string)
pt1, _ := telegraf.NewMetric(
"test_point_1",
tags,
map[string]interface{}{"value": 0.0})
pt2, _ := telegraf.NewMetric(
"test_point_2",
tags,
map[string]interface{}{"value": 1.0})
var metrics = []telegraf.Metric{
pt1,
pt2,
}
require.NoError(t, pTesting.Write(metrics))
expected := []struct {
name string
value float64
tags map[string]string
}{
{"test_point_1", 0.0, tags},
{"test_point_2", 1.0, tags},
}
var acc testutil.Accumulator
require.NoError(t, p.Gather(&acc))
for _, e := range expected {
2016-01-07 17:52:46 +00:00
acc.AssertContainsFields(t, "prometheus_"+e.name,
map[string]interface{}{"value": e.value})
}
tags = make(map[string]string)
tags["testtag"] = "testvalue"
pt3, _ := telegraf.NewMetric(
"test_point_3",
tags,
map[string]interface{}{"value": 0.0})
pt4, _ := telegraf.NewMetric(
"test_point_4",
tags,
map[string]interface{}{"value": 1.0})
metrics = []telegraf.Metric{
pt3,
pt4,
}
require.NoError(t, pTesting.Write(metrics))
expected2 := []struct {
name string
value float64
}{
{"test_point_3", 0.0},
{"test_point_4", 1.0},
}
require.NoError(t, p.Gather(&acc))
for _, e := range expected2 {
2016-01-07 17:52:46 +00:00
acc.AssertContainsFields(t, "prometheus_"+e.name,
map[string]interface{}{"value": e.value})
}
}