From 4b0712995be9445e60bdae3176ffb7854607ae89 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Mon, 23 May 2022 14:13:32 -0600 Subject: [PATCH 1/2] test: move nats to test-containers --- docker-compose.yml | 4 ---- plugins/outputs/nats/nats_test.go | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fb162f5df25f5..86ec1fd03021c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -73,10 +73,6 @@ services: image: open62541/open62541 ports: - "4840:4840" - nats: - image: nats - ports: - - "4222:4222" openldap: image: cobaugh/openldap-alpine environment: diff --git a/plugins/outputs/nats/nats_test.go b/plugins/outputs/nats/nats_test.go index 30004f6ae543d..f8a3d06261a08 100644 --- a/plugins/outputs/nats/nats_test.go +++ b/plugins/outputs/nats/nats_test.go @@ -1,11 +1,13 @@ package nats 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,18 @@ func TestConnectAndWriteIntegration(t *testing.T) { t.Skip("Skipping integration test in short mode") } - server := []string{"nats://" + testutil.GetLocalHost() + ":4222"} + container := testutil.Container{ + Image: "nats", + ExposedPorts: []string{"4222", "6222"}, + WaitingFor: wait.ForLog("Server is ready"), + } + 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("nats://%s:%s", container.Address, container.Port)} s, _ := serializers.NewInfluxSerializer() n := &NATS{ Servers: server, @@ -23,7 +36,7 @@ func TestConnectAndWriteIntegration(t *testing.T) { } // Verify that we can connect to the NATS daemon - err := n.Connect() + err = n.Connect() require.NoError(t, err) // Verify that we can successfully write data to the NATS daemon From c88b93271c6edcec8055e4c32950e13fb5b1e123 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Mon, 23 May 2022 14:14:47 -0600 Subject: [PATCH 2/2] simplify ports --- plugins/outputs/nats/nats_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/outputs/nats/nats_test.go b/plugins/outputs/nats/nats_test.go index f8a3d06261a08..db560d96e91b3 100644 --- a/plugins/outputs/nats/nats_test.go +++ b/plugins/outputs/nats/nats_test.go @@ -17,7 +17,7 @@ func TestConnectAndWriteIntegration(t *testing.T) { container := testutil.Container{ Image: "nats", - ExposedPorts: []string{"4222", "6222"}, + ExposedPorts: []string{"4222"}, WaitingFor: wait.ForLog("Server is ready"), } err := container.Start()