From bdcf8d495de674db37c22e154974bb3be95cd859 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Mon, 23 May 2022 14:57:39 -0600 Subject: [PATCH] test: migrate memcached to test-containers --- docker-compose.yml | 4 ---- plugins/inputs/memcached/memcached_test.go | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fb162f5df25f5..9b446a30ba833 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,10 +34,6 @@ services: - xpack.security.enabled=false ports: - "9200:9200" - memcached: - image: memcached - ports: - - "11211:11211" pgbouncer: image: z9pascal/pgbouncer-container:1.15-latest environment: diff --git a/plugins/inputs/memcached/memcached_test.go b/plugins/inputs/memcached/memcached_test.go index d808057cd54c6..15d6154e37a54 100644 --- a/plugins/inputs/memcached/memcached_test.go +++ b/plugins/inputs/memcached/memcached_test.go @@ -2,10 +2,12 @@ package memcached import ( "bufio" + "fmt" "strings" "testing" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/wait" "github.com/influxdata/telegraf/testutil" ) @@ -15,13 +17,24 @@ func TestMemcachedGeneratesMetricsIntegration(t *testing.T) { t.Skip("Skipping integration test in short mode") } + container := testutil.Container{ + Image: "memcached", + ExposedPorts: []string{"11211"}, + WaitingFor: wait.ForListeningPort("11211/tcp"), + } + err := container.Start() + require.NoError(t, err, "failed to start container") + defer func() { + require.NoError(t, container.Terminate(), "terminating container failed") + }() + m := &Memcached{ - Servers: []string{testutil.GetLocalHost()}, + Servers: []string{fmt.Sprintf("%s:%s", container.Address, container.Port)}, } var acc testutil.Accumulator - err := acc.GatherError(m.Gather) + err = acc.GatherError(m.Gather) require.NoError(t, err) intMetrics := []string{"get_hits", "get_misses", "evictions",