From 43c9e051b599ca11e5b42f453507abb26e743b0b Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Thu, 2 Jun 2022 07:48:04 -0600 Subject: [PATCH] test: migrate mcrouter to test-containers (#11208) --- plugins/inputs/mcrouter/mcrouter_test.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/mcrouter/mcrouter_test.go b/plugins/inputs/mcrouter/mcrouter_test.go index f02f2b53d..5e5adbc53 100644 --- a/plugins/inputs/mcrouter/mcrouter_test.go +++ b/plugins/inputs/mcrouter/mcrouter_test.go @@ -2,10 +2,13 @@ package mcrouter import ( "bufio" + "fmt" "strings" "testing" + "github.com/docker/go-connections/nat" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/wait" "github.com/influxdata/telegraf/testutil" ) @@ -49,13 +52,27 @@ func TestMcrouterGeneratesMetricsIntegration(t *testing.T) { t.Skip("Skipping integration test in short mode") } + servicePort := "11211" + container := testutil.Container{ + Image: "memcached", + ExposedPorts: []string{servicePort}, + WaitingFor: wait.ForListeningPort(nat.Port(servicePort)), + } + err := container.Start() + require.NoError(t, err, "failed to start container") + defer func() { + require.NoError(t, container.Terminate(), "terminating container failed") + }() + m := &Mcrouter{ - Servers: []string{"tcp://" + testutil.GetLocalHost()}, + Servers: []string{ + fmt.Sprintf("tcp://%s:%s", container.Address, container.Ports[servicePort]), + }, } var acc testutil.Accumulator - err := acc.GatherError(m.Gather) + err = acc.GatherError(m.Gather) require.NoError(t, err) intMetrics := []string{