MQTT output unit tests w/ docker container

This commit is contained in:
Cameron Sparr 2015-11-13 13:37:24 -07:00
parent b975419bc7
commit a6ae597dfc
2 changed files with 31 additions and 2 deletions

View File

@ -56,6 +56,7 @@ endif
docker run --name redis -p "6379:6379" -d redis docker run --name redis -p "6379:6379" -d redis
docker run --name aerospike -p "3000:3000" -d aerospike docker run --name aerospike -p "3000:3000" -d aerospike
docker run --name nsq -p "4150:4150" -d nsqio/nsq /nsqd 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 # Run docker containers necessary for CircleCI unit tests
docker-run-circle: docker-run-circle:
@ -67,11 +68,12 @@ docker-run-circle:
docker run --name opentsdb -p "4242:4242" -d petergrace/opentsdb-docker docker run --name opentsdb -p "4242:4242" -d petergrace/opentsdb-docker
docker run --name aerospike -p "3000:3000" -d aerospike docker run --name aerospike -p "3000:3000" -d aerospike
docker run --name nsq -p "4150:4150" -d nsqio/nsq /nsqd 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 # Kill all docker containers, ignore errors
docker-kill: docker-kill:
-docker kill 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 -docker rm nsq aerospike redis opentsdb rabbitmq postgres memcached mysql kafka mqtt
# Run full unit tests using docker containers (includes setup and teardown) # Run full unit tests using docker containers (includes setup and teardown)
test: docker-kill prepare docker-run test: docker-kill prepare docker-run

27
outputs/mqtt/mqtt_test.go Normal file
View File

@ -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)
}