Skip to content

Commit

Permalink
test: migrate nsq to test containers
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed May 24, 2022
1 parent b5e5f4c commit d17c8de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ services:
image: redis:alpine
ports:
- "6379:6379"
nsq:
image: nsqio/nsq
ports:
- "4150:4150"
command: "/nsqd"
mqtt:
image: ncarlier/mqtt
ports:
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: 2 additions & 0 deletions testutil/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

type Container struct {
Image string
Entrypoint []string
Env map[string]string
ExposedPorts []string
WaitingFor wait.Strategy
Expand All @@ -33,6 +34,7 @@ func (c *Container) Start() error {
Image: c.Image,
Env: c.Env,
ExposedPorts: c.ExposedPorts,
Entrypoint: c.Entrypoint,
WaitingFor: c.WaitingFor,
},
Started: true,
Expand Down

0 comments on commit d17c8de

Please sign in to comment.