From 1d608d9f02ef124d5c16858b74885d0379930477 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Mon, 23 May 2022 14:39:29 -0600 Subject: [PATCH] test: migrate nsq to test containers --- docker-compose.yml | 5 ----- plugins/outputs/nsq/nsq_test.go | 18 ++++++++++++++++-- testutil/container.go | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c6b3c19accefe..689f8fbef449f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,11 +52,6 @@ services: ports: - "15672:15672" - "5672:5672" - nsq: - image: nsqio/nsq - ports: - - "4150:4150" - command: "/nsqd" opcua: image: open62541/open62541 ports: diff --git a/plugins/outputs/nsq/nsq_test.go b/plugins/outputs/nsq/nsq_test.go index f7f55ddf34d07..50f2a41d527ca 100644 --- a/plugins/outputs/nsq/nsq_test.go +++ b/plugins/outputs/nsq/nsq_test.go @@ -1,11 +1,13 @@ package nsq import ( + "fmt" "testing" "github.com/influxdata/telegraf/plugins/serializers" "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/wait" ) func TestConnectAndWriteIntegration(t *testing.T) { @@ -13,7 +15,19 @@ func TestConnectAndWriteIntegration(t *testing.T) { t.Skip("Skipping integration test in short mode") } - server := []string{testutil.GetLocalHost() + ":4150"} + container := testutil.Container{ + Image: "nsqio/nsq", + ExposedPorts: []string{"4150"}, + Entrypoint: []string{"/nsqd"}, + WaitingFor: wait.ForListeningPort("4150/tcp"), + } + err := container.Start() + require.NoError(t, err, "failed to start container") + defer func() { + require.NoError(t, container.Terminate(), "terminating container failed") + }() + + server := []string{fmt.Sprintf("%s:%s", container.Address, container.Port)} s, _ := serializers.NewInfluxSerializer() n := &NSQ{ Server: server[0], @@ -22,7 +36,7 @@ func TestConnectAndWriteIntegration(t *testing.T) { } // Verify that we can connect to the NSQ daemon - err := n.Connect() + err = n.Connect() require.NoError(t, err) // Verify that we can successfully write data to the NSQ daemon diff --git a/testutil/container.go b/testutil/container.go index 45ffe8757ef77..7144d7399a425 100644 --- a/testutil/container.go +++ b/testutil/container.go @@ -34,6 +34,7 @@ func (c *Container) Start() error { Image: c.Image, Env: c.Env, ExposedPorts: c.ExposedPorts, + Entrypoint: c.Entrypoint, WaitingFor: c.WaitingFor, Entrypoint: c.Entrypoint, },