Skip to content

Commit

Permalink
MQTT output unit tests w/ docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Nov 13, 2015
1 parent b975419 commit a6ae597
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions outputs/mqtt/mqtt_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit a6ae597

Please sign in to comment.