Skip to content

Commit

Permalink
test: migrate zookeeper to test-containers (#11185)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored May 25, 2022
1 parent d51634a commit b295037
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions plugins/inputs/zookeeper/zookeeper_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package zookeeper

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/influxdata/telegraf/testutil"
)
Expand All @@ -13,16 +15,31 @@ func TestZookeeperGeneratesMetricsIntegration(t *testing.T) {
t.Skip("Skipping integration test in short mode")
}

container := testutil.Container{
Image: "zookeeper",
ExposedPorts: []string{"2181"},
Env: map[string]string{
"ZOO_4LW_COMMANDS_WHITELIST": "mntr",
},
WaitingFor: wait.ForListeningPort("2181"),
}
err := container.Start()
require.NoError(t, err, "failed to start container")
defer func() {
require.NoError(t, container.Terminate(), "terminating container failed")
}()

z := &Zookeeper{
Servers: []string{testutil.GetLocalHost() + ":2181"},
Servers: []string{
fmt.Sprintf("%s:%s", container.Address, container.Port),
},
}

var acc testutil.Accumulator

require.NoError(t, acc.GatherError(z.Gather))

intMetrics := []string{
"avg_latency",
"max_latency",
"min_latency",
"packets_received",
Expand All @@ -39,4 +56,8 @@ func TestZookeeperGeneratesMetricsIntegration(t *testing.T) {
for _, metric := range intMetrics {
require.True(t, acc.HasInt64Field("zookeeper", metric), metric)
}

// Currently we output floats as strings (see #8863), but the desired behavior is to have floats
require.True(t, acc.HasStringField("zookeeper", "avg_latency"), "avg_latency")
// require.True(t, acc.HasFloat64Field("zookeeper", "avg_latency"), "avg_latency")
}

0 comments on commit b295037

Please sign in to comment.