From 3e52fb38f85f2ce9bf3db4dc27d1ef63d6678b0c Mon Sep 17 00:00:00 2001 From: deadprogram Date: Thu, 2 Feb 2017 16:30:15 +0100 Subject: [PATCH] nats: use new improved default namer to avoid API conflicts Signed-off-by: deadprogram --- platforms/nats/nats_adaptor.go | 7 +++++-- platforms/nats/nats_driver.go | 2 +- platforms/nats/nats_driver_test.go | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/platforms/nats/nats_adaptor.go b/platforms/nats/nats_adaptor.go index 32484565..1e08c21f 100644 --- a/platforms/nats/nats_adaptor.go +++ b/platforms/nats/nats_adaptor.go @@ -1,6 +1,9 @@ package nats -import "github.com/nats-io/nats" +import ( + "github.com/nats-io/nats" + "gobot.io/x/gobot" +) // Adaptor is a configuration struct for interacting with a NATS server. // Name is a logical name for the adaptor/nats server connection. @@ -19,7 +22,7 @@ type Adaptor struct { // NewAdaptor populates a new NATS Adaptor. func NewAdaptor(host string, clientID int) *Adaptor { return &Adaptor{ - name: "NATS", + name: gobot.DefaultName("NATS"), Host: host, clientID: clientID, connect: func() (*nats.Conn, error) { diff --git a/platforms/nats/nats_driver.go b/platforms/nats/nats_driver.go index 59507c6f..be47c7de 100644 --- a/platforms/nats/nats_driver.go +++ b/platforms/nats/nats_driver.go @@ -22,7 +22,7 @@ type Driver struct { // NewDriver returns a new Gobot NATS Driver func NewDriver(a *Adaptor, topic string) *Driver { m := &Driver{ - name: "NATS", + name: gobot.DefaultName("NATS"), topic: topic, connection: a, Eventer: gobot.NewEventer(), diff --git a/platforms/nats/nats_driver_test.go b/platforms/nats/nats_driver_test.go index e5288815..d0b58586 100644 --- a/platforms/nats/nats_driver_test.go +++ b/platforms/nats/nats_driver_test.go @@ -1,6 +1,7 @@ package nats import ( + "strings" "testing" "gobot.io/x/gobot" @@ -12,8 +13,8 @@ var _ gobot.Driver = (*Driver)(nil) func TestNatsDriver(t *testing.T) { d := NewDriver(initTestNatsAdaptor(), "/test/topic") - gobottest.Assert(t, d.Name(), "NATS") - gobottest.Assert(t, d.Connection().Name(), "NATS") + gobottest.Assert(t, strings.HasPrefix(d.Name(), "NATS"), true) + gobottest.Assert(t, strings.HasPrefix(d.Connection().Name(), "NATS"), true) gobottest.Assert(t, d.Start(), nil) gobottest.Assert(t, d.Halt(), nil)