mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-02 22:17:12 +08:00
Fixing tests, adding a few more, adding nats server to Travis CI for testing
Signed-off-by: Cale Hoopes <caledh@gmail.com>
This commit is contained in:
parent
e7839a8924
commit
cca8b5624b
@ -19,6 +19,11 @@ before_install:
|
|||||||
- sudo apt-get install --force-yes libcv-dev libcvaux-dev libhighgui-dev libopencv-dev libsdl2-dev libsdl2-image-dev libsdl2 libusb-dev xvfb libgtk2.0-0
|
- sudo apt-get install --force-yes libcv-dev libcvaux-dev libhighgui-dev libopencv-dev libsdl2-dev libsdl2-image-dev libsdl2 libusb-dev xvfb libgtk2.0-0
|
||||||
- go get github.com/axw/gocov/gocov
|
- go get github.com/axw/gocov/gocov
|
||||||
- go get github.com/mattn/goveralls
|
- go get github.com/mattn/goveralls
|
||||||
|
- mkdir -p gnatsd
|
||||||
|
- "wget https://github.com/nats-io/gnatsd/releases/download/v0.8.1/gnatsd-v0.8.1-linux-amd64.zip -qO - | tar -zxvC gnatsd/"
|
||||||
|
- export PATH=$PATH:$PWD/gnatsd/
|
||||||
|
- gnatsd -p 4222 &
|
||||||
|
- gnatsd -p 4223 --user test --pass testwd &
|
||||||
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
|
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
|
||||||
install:
|
install:
|
||||||
- go get -d -v ./...
|
- go get -d -v ./...
|
||||||
|
@ -10,45 +10,54 @@ import (
|
|||||||
|
|
||||||
var _ gobot.Adaptor = (*NatsAdaptor)(nil)
|
var _ gobot.Adaptor = (*NatsAdaptor)(nil)
|
||||||
|
|
||||||
func initTestNatsAdaptor() *NatsAdaptor {
|
|
||||||
return NewNatsAdaptor("Nats", "localhost:4222", 9999)
|
|
||||||
}
|
|
||||||
|
|
||||||
// These tests only succeed when there is a nats server available
|
|
||||||
func TestNatsAdaptorPublishWhenConnected(t *testing.T) {
|
func TestNatsAdaptorPublishWhenConnected(t *testing.T) {
|
||||||
a := initTestNatsAdaptor()
|
a := NewNatsAdaptor("Nats", "localhost:4222", 9999)
|
||||||
a.Connect()
|
a.Connect()
|
||||||
data := []byte("o")
|
data := []byte("o")
|
||||||
gobottest.Assert(t, a.Publish("test", data), true)
|
gobottest.Assert(t, a.Publish("test", data), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNatsAdaptorOnWhenConnected(t *testing.T) {
|
func TestNatsAdaptorOnWhenConnected(t *testing.T) {
|
||||||
a := initTestNatsAdaptor()
|
a := NewNatsAdaptor("Nats", "localhost:4222", 9999)
|
||||||
|
a.Connect()
|
||||||
|
gobottest.Assert(t, a.On("hola", func(data []byte) {
|
||||||
|
fmt.Println("hola")
|
||||||
|
}), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNatsAdaptorPublishWhenConnectedWithAuth(t *testing.T) {
|
||||||
|
a := NewNatsAdaptorWithAuth("Nats", "localhost:4222", 9999, "test", "testwd")
|
||||||
|
a.Connect()
|
||||||
|
data := []byte("o")
|
||||||
|
gobottest.Assert(t, a.Publish("test", data), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNatsAdaptorOnWhenConnectedWithAuth(t *testing.T) {
|
||||||
|
a := NewNatsAdaptorWithAuth("Nats", "localhost:4222", 9999, "test", "testwd")
|
||||||
a.Connect()
|
a.Connect()
|
||||||
gobottest.Assert(t, a.On("hola", func(data []byte) {
|
gobottest.Assert(t, a.On("hola", func(data []byte) {
|
||||||
fmt.Println("hola")
|
fmt.Println("hola")
|
||||||
}), true)
|
}), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// These tests only succeed when there is no nats server available
|
|
||||||
func TestNatsAdaptorConnect(t *testing.T) {
|
func TestNatsAdaptorConnect(t *testing.T) {
|
||||||
a := initTestNatsAdaptor()
|
a := NewNatsAdaptor("Nats", "localhost:9999", 9999)
|
||||||
gobottest.Assert(t, a.Connect()[0].Error(), "nats: no servers available for connection")
|
gobottest.Assert(t, a.Connect()[0].Error(), "nats: no servers available for connection")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNatsAdaptorFinalize(t *testing.T) {
|
func TestNatsAdaptorFinalize(t *testing.T) {
|
||||||
a := initTestNatsAdaptor()
|
a := NewNatsAdaptor("Nats", "localhost:9999", 9999)
|
||||||
gobottest.Assert(t, len(a.Finalize()), 0)
|
gobottest.Assert(t, len(a.Finalize()), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNatsAdaptorCannotPublishUnlessConnected(t *testing.T) {
|
func TestNatsAdaptorCannotPublishUnlessConnected(t *testing.T) {
|
||||||
a := initTestNatsAdaptor()
|
a := NewNatsAdaptor("Nats", "localhost:9999", 9999)
|
||||||
data := []byte("o")
|
data := []byte("o")
|
||||||
gobottest.Assert(t, a.Publish("test", data), false)
|
gobottest.Assert(t, a.Publish("test", data), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNatsAdaptorCannotOnUnlessConnected(t *testing.T) {
|
func TestNatsAdaptorCannotOnUnlessConnected(t *testing.T) {
|
||||||
a := initTestNatsAdaptor()
|
a := NewNatsAdaptor("Nats", "localhost:9999", 9999)
|
||||||
gobottest.Assert(t, a.On("hola", func(data []byte) {
|
gobottest.Assert(t, a.On("hola", func(data []byte) {
|
||||||
fmt.Println("hola")
|
fmt.Println("hola")
|
||||||
}), false)
|
}), false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user