test: migrate mqtt to test containers (#11172)
This commit is contained in:
parent
03034cd1d1
commit
dd8dd75824
|
|
@ -65,10 +65,6 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "4150:4150"
|
- "4150:4150"
|
||||||
command: "/nsqd"
|
command: "/nsqd"
|
||||||
mqtt:
|
|
||||||
image: ncarlier/mqtt
|
|
||||||
ports:
|
|
||||||
- "1883:1883"
|
|
||||||
opcua:
|
opcua:
|
||||||
image: open62541/open62541
|
image: open62541/open62541
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package mqtt
|
package mqtt
|
||||||
|
|
||||||
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/testcontainers/testcontainers-go/wait"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
@ -14,7 +16,18 @@ func TestConnectAndWriteIntegration(t *testing.T) {
|
||||||
t.Skip("Skipping integration test in short mode")
|
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()
|
s, _ := serializers.NewInfluxSerializer()
|
||||||
m := &MQTT{
|
m := &MQTT{
|
||||||
Servers: []string{url},
|
Servers: []string{url},
|
||||||
|
|
@ -23,7 +36,7 @@ func TestConnectAndWriteIntegration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that we can connect to the MQTT broker
|
// Verify that we can connect to the MQTT broker
|
||||||
err := m.Connect()
|
err = m.Connect()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Verify that we can successfully write data to the mqtt broker
|
// Verify that we can successfully write data to the mqtt broker
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue