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: migrate mqtt to test containers #11172

Merged
merged 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -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