1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/platforms/mqtt/mqtt_adaptor_test.go
Damian Gryski b5083e67d3 Move interface assertions to test files.
In general, these shouldn't live in the package proper, since they're
actually tests.
2016-07-13 11:04:30 -06:00

54 lines
1.2 KiB
Go

package mqtt
import (
"fmt"
"testing"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
)
var _ gobot.Adaptor = (*MqttAdaptor)(nil)
func initTestMqttAdaptor() *MqttAdaptor {
return NewMqttAdaptor("mqtt", "localhost:1883", "client")
}
func TestMqttAdaptorConnect(t *testing.T) {
a := initTestMqttAdaptor()
gobottest.Assert(t, a.Connect()[0].Error(), "Network Error : Unknown protocol")
}
func TestMqttAdaptorFinalize(t *testing.T) {
a := initTestMqttAdaptor()
gobottest.Assert(t, len(a.Finalize()), 0)
}
func TestMqttAdaptorCannotPublishUnlessConnected(t *testing.T) {
a := initTestMqttAdaptor()
data := []byte("o")
gobottest.Assert(t, a.Publish("test", data), false)
}
func TestMqttAdaptorPublishWhenConnected(t *testing.T) {
a := initTestMqttAdaptor()
a.Connect()
data := []byte("o")
gobottest.Assert(t, a.Publish("test", data), true)
}
func TestMqttAdaptorCannotOnUnlessConnected(t *testing.T) {
a := initTestMqttAdaptor()
gobottest.Assert(t, a.On("hola", func(data []byte) {
fmt.Println("hola")
}), false)
}
func TestMqttAdaptorOnWhenConnected(t *testing.T) {
a := initTestMqttAdaptor()
a.Connect()
gobottest.Assert(t, a.On("hola", func(data []byte) {
fmt.Println("hola")
}), true)
}