Skip to content

Commit

Permalink
Fixing tests, adding a few more, adding nats server to Travis CI for …
Browse files Browse the repository at this point in the history
…testing

Signed-off-by: Cale Hoopes <[email protected]>
  • Loading branch information
caledhwa committed Jul 17, 2016
1 parent e7839a8 commit cca8b56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- go get github.com/axw/gocov/gocov
- 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
install:
- go get -d -v ./...
Expand Down
33 changes: 21 additions & 12 deletions platforms/nats/nats_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,54 @@ import (

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) {
a := initTestNatsAdaptor()
a := NewNatsAdaptor("Nats", "localhost:4222", 9999)
a.Connect()
data := []byte("o")
gobottest.Assert(t, a.Publish("test", data), true)
}

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()
gobottest.Assert(t, a.On("hola", func(data []byte) {
fmt.Println("hola")
}), true)
}

// These tests only succeed when there is no nats server available
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")
}

func TestNatsAdaptorFinalize(t *testing.T) {
a := initTestNatsAdaptor()
a := NewNatsAdaptor("Nats", "localhost:9999", 9999)
gobottest.Assert(t, len(a.Finalize()), 0)
}

func TestNatsAdaptorCannotPublishUnlessConnected(t *testing.T) {
a := initTestNatsAdaptor()
a := NewNatsAdaptor("Nats", "localhost:9999", 9999)
data := []byte("o")
gobottest.Assert(t, a.Publish("test", data), false)
}

func TestNatsAdaptorCannotOnUnlessConnected(t *testing.T) {
a := initTestNatsAdaptor()
a := NewNatsAdaptor("Nats", "localhost:9999", 9999)
gobottest.Assert(t, a.On("hola", func(data []byte) {
fmt.Println("hola")
}), false)
Expand Down

0 comments on commit cca8b56

Please sign in to comment.