From a6ae597dfcb3412a5b074fca4b79d89a77c84d31 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Fri, 13 Nov 2015 13:37:24 -0700 Subject: [PATCH] MQTT output unit tests w/ docker container --- Makefile | 6 ++++-- outputs/mqtt/mqtt_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 outputs/mqtt/mqtt_test.go diff --git a/Makefile b/Makefile index 417b0e990..49e571ef8 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,7 @@ endif docker run --name redis -p "6379:6379" -d redis docker run --name aerospike -p "3000:3000" -d aerospike docker run --name nsq -p "4150:4150" -d nsqio/nsq /nsqd + docker run --name mqtt -p "1883:1883" -d ncarlier/mqtt # Run docker containers necessary for CircleCI unit tests docker-run-circle: @@ -67,11 +68,12 @@ docker-run-circle: docker run --name opentsdb -p "4242:4242" -d petergrace/opentsdb-docker docker run --name aerospike -p "3000:3000" -d aerospike docker run --name nsq -p "4150:4150" -d nsqio/nsq /nsqd + docker run --name mqtt -p "1883:1883" -d ncarlier/mqtt # Kill all docker containers, ignore errors docker-kill: - -docker kill nsq aerospike redis opentsdb rabbitmq postgres memcached mysql kafka - -docker rm nsq aerospike redis opentsdb rabbitmq postgres memcached mysql kafka + -docker kill nsq aerospike redis opentsdb rabbitmq postgres memcached mysql kafka mqtt + -docker rm nsq aerospike redis opentsdb rabbitmq postgres memcached mysql kafka mqtt # Run full unit tests using docker containers (includes setup and teardown) test: docker-kill prepare docker-run diff --git a/outputs/mqtt/mqtt_test.go b/outputs/mqtt/mqtt_test.go new file mode 100644 index 000000000..0922b83ed --- /dev/null +++ b/outputs/mqtt/mqtt_test.go @@ -0,0 +1,27 @@ +package mqtt + +import ( + "testing" + + "github.com/influxdb/telegraf/testutil" + "github.com/stretchr/testify/require" +) + +func TestConnectAndWrite(t *testing.T) { + if testing.Short() { + t.Skip("Skipping integration test in short mode") + } + + var url = testutil.GetLocalHost() + ":1883" + m := &MQTT{ + Servers: []string{url}, + } + + // Verify that we can connect to the MQTT broker + err := m.Connect() + require.NoError(t, err) + + // Verify that we can successfully write data to the mqtt broker + err = m.Write(testutil.MockBatchPoints().Points()) + require.NoError(t, err) +}