Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move nats to test-containers #11170

Merged
merged 2 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ services:
image: open62541/open62541
ports:
- "4840:4840"
nats:
image: nats
ports:
- "4222:4222"
openldap:
image: cobaugh/openldap-alpine
environment:
Expand Down
17 changes: 15 additions & 2 deletions plugins/outputs/nats/nats_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
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) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}

server := []string{"nats://" + testutil.GetLocalHost() + ":4222"}
container := testutil.Container{
Image: "nats",
ExposedPorts: []string{"4222"},
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,
Expand All @@ -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
Expand Down