mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-27 13:48:56 +08:00
nats: use new improved default namer to avoid API conflicts
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
254068c14d
commit
3e52fb38f8
@ -1,6 +1,9 @@
|
|||||||
package nats
|
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.
|
// Adaptor is a configuration struct for interacting with a NATS server.
|
||||||
// Name is a logical name for the adaptor/nats server connection.
|
// Name is a logical name for the adaptor/nats server connection.
|
||||||
@ -19,7 +22,7 @@ type Adaptor struct {
|
|||||||
// NewAdaptor populates a new NATS Adaptor.
|
// NewAdaptor populates a new NATS Adaptor.
|
||||||
func NewAdaptor(host string, clientID int) *Adaptor {
|
func NewAdaptor(host string, clientID int) *Adaptor {
|
||||||
return &Adaptor{
|
return &Adaptor{
|
||||||
name: "NATS",
|
name: gobot.DefaultName("NATS"),
|
||||||
Host: host,
|
Host: host,
|
||||||
clientID: clientID,
|
clientID: clientID,
|
||||||
connect: func() (*nats.Conn, error) {
|
connect: func() (*nats.Conn, error) {
|
||||||
|
@ -22,7 +22,7 @@ type Driver struct {
|
|||||||
// NewDriver returns a new Gobot NATS Driver
|
// NewDriver returns a new Gobot NATS Driver
|
||||||
func NewDriver(a *Adaptor, topic string) *Driver {
|
func NewDriver(a *Adaptor, topic string) *Driver {
|
||||||
m := &Driver{
|
m := &Driver{
|
||||||
name: "NATS",
|
name: gobot.DefaultName("NATS"),
|
||||||
topic: topic,
|
topic: topic,
|
||||||
connection: a,
|
connection: a,
|
||||||
Eventer: gobot.NewEventer(),
|
Eventer: gobot.NewEventer(),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package nats
|
package nats
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gobot.io/x/gobot"
|
"gobot.io/x/gobot"
|
||||||
@ -12,8 +13,8 @@ var _ gobot.Driver = (*Driver)(nil)
|
|||||||
func TestNatsDriver(t *testing.T) {
|
func TestNatsDriver(t *testing.T) {
|
||||||
d := NewDriver(initTestNatsAdaptor(), "/test/topic")
|
d := NewDriver(initTestNatsAdaptor(), "/test/topic")
|
||||||
|
|
||||||
gobottest.Assert(t, d.Name(), "NATS")
|
gobottest.Assert(t, strings.HasPrefix(d.Name(), "NATS"), true)
|
||||||
gobottest.Assert(t, d.Connection().Name(), "NATS")
|
gobottest.Assert(t, strings.HasPrefix(d.Connection().Name(), "NATS"), true)
|
||||||
|
|
||||||
gobottest.Assert(t, d.Start(), nil)
|
gobottest.Assert(t, d.Start(), nil)
|
||||||
gobottest.Assert(t, d.Halt(), nil)
|
gobottest.Assert(t, d.Halt(), nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user