test: migrate mqtt to test containers (#11172)
This commit is contained in:
parent
03034cd1d1
commit
dd8dd75824
|
|
@ -65,10 +65,6 @@ services:
|
|||
ports:
|
||||
- "4150:4150"
|
||||
command: "/nsqd"
|
||||
mqtt:
|
||||
image: ncarlier/mqtt
|
||||
ports:
|
||||
- "1883:1883"
|
||||
opcua:
|
||||
image: open62541/open62541
|
||||
ports:
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -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},
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue