Skip to content

Commit

Permalink
test: migrate mqtt to test containers (#11172)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored May 24, 2022
1 parent 03034cd commit dd8dd75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ services:
ports:
- "4150:4150"
command: "/nsqd"
mqtt:
image: ncarlier/mqtt
ports:
- "1883:1883"
opcua:
image: open62541/open62541
ports:
Expand Down
17 changes: 15 additions & 2 deletions plugins/outputs/mqtt/mqtt_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package mqtt

import (
"fmt"
"testing"

"github.com/influxdata/telegraf/plugins/serializers"
"github.com/influxdata/telegraf/testutil"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/stretchr/testify/require"
)
Expand All @@ -14,7 +16,18 @@ func TestConnectAndWriteIntegration(t *testing.T) {
t.Skip("Skipping integration test in short mode")
}

var url = testutil.GetLocalHost() + ":1883"
container := testutil.Container{
Image: "ncarlier/mqtt",
ExposedPorts: []string{"1883"},
WaitingFor: wait.ForListeningPort("1883/tcp"),
}
err := container.Start()
require.NoError(t, err, "failed to start container")
defer func() {
require.NoError(t, container.Terminate(), "terminating container failed")
}()

var url = fmt.Sprintf("%s:%s", container.Address, container.Port)
s, _ := serializers.NewInfluxSerializer()
m := &MQTT{
Servers: []string{url},
Expand All @@ -23,7 +36,7 @@ func TestConnectAndWriteIntegration(t *testing.T) {
}

// Verify that we can connect to the MQTT broker
err := m.Connect()
err = m.Connect()
require.NoError(t, err)

// Verify that we can successfully write data to the mqtt broker
Expand Down

0 comments on commit dd8dd75

Please sign in to comment.