Skip to content

Commit

Permalink
test: migrate nsq to test containers (#11173)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored May 24, 2022
1 parent d5ff34b commit 5857966
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ services:
ports:
- "15672:15672"
- "5672:5672"
nsq:
image: nsqio/nsq
ports:
- "4150:4150"
command: "/nsqd"
openldap:
image: cobaugh/openldap-alpine
environment:
Expand Down
18 changes: 16 additions & 2 deletions plugins/outputs/nsq/nsq_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
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) {
if testing.Short() {
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],
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testutil/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func (c *Container) Start() error {
Image: c.Image,
Env: c.Env,
ExposedPorts: c.ExposedPorts,
WaitingFor: c.WaitingFor,
Entrypoint: c.Entrypoint,
WaitingFor: c.WaitingFor,
},
Started: true,
}
Expand Down

0 comments on commit 5857966

Please sign in to comment.