test: migrate nsq to test containers (#11173)

This commit is contained in:
Joshua Powers 2022-05-24 10:31:49 -06:00 committed by GitHub
parent d5ff34bc14
commit 5857966df1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View File

@ -45,11 +45,6 @@ services:
ports: ports:
- "15672:15672" - "15672:15672"
- "5672:5672" - "5672:5672"
nsq:
image: nsqio/nsq
ports:
- "4150:4150"
command: "/nsqd"
openldap: openldap:
image: cobaugh/openldap-alpine image: cobaugh/openldap-alpine
environment: environment:

View File

@ -1,11 +1,13 @@
package nsq package nsq
import ( import (
"fmt"
"testing" "testing"
"github.com/influxdata/telegraf/plugins/serializers" "github.com/influxdata/telegraf/plugins/serializers"
"github.com/influxdata/telegraf/testutil" "github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go/wait"
) )
func TestConnectAndWriteIntegration(t *testing.T) { func TestConnectAndWriteIntegration(t *testing.T) {
@ -13,7 +15,19 @@ func TestConnectAndWriteIntegration(t *testing.T) {
t.Skip("Skipping integration test in short mode") 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() s, _ := serializers.NewInfluxSerializer()
n := &NSQ{ n := &NSQ{
Server: server[0], Server: server[0],
@ -22,7 +36,7 @@ func TestConnectAndWriteIntegration(t *testing.T) {
} }
// Verify that we can connect to the NSQ daemon // Verify that we can connect to the NSQ daemon
err := n.Connect() err = n.Connect()
require.NoError(t, err) require.NoError(t, err)
// Verify that we can successfully write data to the NSQ daemon // Verify that we can successfully write data to the NSQ daemon

View File

@ -34,8 +34,8 @@ func (c *Container) Start() error {
Image: c.Image, Image: c.Image,
Env: c.Env, Env: c.Env,
ExposedPorts: c.ExposedPorts, ExposedPorts: c.ExposedPorts,
WaitingFor: c.WaitingFor,
Entrypoint: c.Entrypoint, Entrypoint: c.Entrypoint,
WaitingFor: c.WaitingFor,
}, },
Started: true, Started: true,
} }