diff --git a/docker-compose.yml b/docker-compose.yml index fb162f5df25f5..d6f2091be0679 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,10 +65,6 @@ services: ports: - "4150:4150" command: "/nsqd" - mqtt: - image: ncarlier/mqtt - ports: - - "1883:1883" opcua: image: open62541/open62541 ports: diff --git a/plugins/outputs/mqtt/mqtt_test.go b/plugins/outputs/mqtt/mqtt_test.go index fd36d6d0577ac..8a3471232eb7a 100644 --- a/plugins/outputs/mqtt/mqtt_test.go +++ b/plugins/outputs/mqtt/mqtt_test.go @@ -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