diff --git a/platforms/mqtt/mqtt_adaptor.go b/platforms/mqtt/mqtt_adaptor.go index 0b30d0ae..59152205 100644 --- a/platforms/mqtt/mqtt_adaptor.go +++ b/platforms/mqtt/mqtt_adaptor.go @@ -1,6 +1,9 @@ package mqtt -import paho "github.com/eclipse/paho.mqtt.golang" +import ( + paho "github.com/eclipse/paho.mqtt.golang" + multierror "github.com/hashicorp/go-multierror" +) type Adaptor struct { name string @@ -34,10 +37,10 @@ func (a *Adaptor) Name() string { return a.name } func (a *Adaptor) SetName(n string) { a.name = n } // Connect returns true if connection to mqtt is established -func (a *Adaptor) Connect() (errs []error) { +func (a *Adaptor) Connect() (err error) { a.client = paho.NewClient(createClientOptions(a.clientID, a.Host, a.username, a.password)) if token := a.client.Connect(); token.Wait() && token.Error() != nil { - errs = append(errs, token.Error()) + err = multierror.Append(err, token.Error()) } return @@ -52,7 +55,7 @@ func (a *Adaptor) Disconnect() (err error) { } // Finalize returns true if connection to mqtt is finalized successfully -func (a *Adaptor) Finalize() (errs []error) { +func (a *Adaptor) Finalize() (err error) { a.Disconnect() return } diff --git a/platforms/mqtt/mqtt_adaptor_test.go b/platforms/mqtt/mqtt_adaptor_test.go index 5e275f9d..e56be508 100644 --- a/platforms/mqtt/mqtt_adaptor_test.go +++ b/platforms/mqtt/mqtt_adaptor_test.go @@ -16,12 +16,12 @@ func initTestMqttAdaptor() *Adaptor { func TestMqttAdaptorConnect(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.Connect()[0].Error(), "Network Error : Unknown protocol") + gobottest.Assert(t, a.Connect().Error(), "1 error(s) occurred:\n\n* Network Error : Unknown protocol") } func TestMqttAdaptorFinalize(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, len(a.Finalize()), 0) + gobottest.Assert(t, a.Finalize(), nil) } func TestMqttAdaptorCannotPublishUnlessConnected(t *testing.T) {