2017-02-01 04:13:35 +08:00
|
|
|
package nats
|
|
|
|
|
|
|
|
import (
|
2017-02-02 23:30:15 +08:00
|
|
|
"strings"
|
2017-02-01 04:13:35 +08:00
|
|
|
"testing"
|
|
|
|
|
2023-10-20 16:27:09 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-11-12 21:17:02 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-11-16 03:51:52 +08:00
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
2017-02-01 04:13:35 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ gobot.Driver = (*Driver)(nil)
|
|
|
|
|
|
|
|
func TestNatsDriver(t *testing.T) {
|
|
|
|
d := NewDriver(initTestNatsAdaptor(), "/test/topic")
|
|
|
|
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.True(t, strings.HasPrefix(d.Name(), "NATS"))
|
|
|
|
assert.True(t, strings.HasPrefix(d.Connection().Name(), "NATS"))
|
|
|
|
assert.NotNil(t, d.adaptor())
|
2017-02-01 04:13:35 +08:00
|
|
|
|
2023-11-12 21:17:02 +08:00
|
|
|
require.NoError(t, d.Start())
|
|
|
|
require.NoError(t, d.Halt())
|
2017-02-01 04:13:35 +08:00
|
|
|
}
|
2017-04-06 16:56:49 +08:00
|
|
|
|
|
|
|
func TestNatsDriverName(t *testing.T) {
|
|
|
|
d := NewDriver(initTestNatsAdaptor(), "/test/topic")
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.True(t, strings.HasPrefix(d.Name(), "NATS"))
|
2017-04-06 16:56:49 +08:00
|
|
|
d.SetName("NewName")
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.Equal(t, "NewName", d.Name())
|
2017-04-06 16:56:49 +08:00
|
|
|
}
|
2017-04-29 19:40:27 +08:00
|
|
|
|
|
|
|
func TestNatsDriverTopic(t *testing.T) {
|
|
|
|
d := NewDriver(initTestNatsAdaptor(), "/test/topic")
|
|
|
|
d.SetTopic("interestingtopic")
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.Equal(t, "interestingtopic", d.Topic())
|
2017-04-29 19:40:27 +08:00
|
|
|
}
|