Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Apr 15, 2014
1 parent afa6cf1 commit 9875101
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 97 deletions.
36 changes: 0 additions & 36 deletions connection_test.go

This file was deleted.

30 changes: 0 additions & 30 deletions device_test.go

This file was deleted.

21 changes: 16 additions & 5 deletions master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gobot
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"os"
)

var _ = Describe("Master", func() {
Expand All @@ -12,15 +13,13 @@ var _ = Describe("Master", func() {

BeforeEach(func() {
myMaster = GobotMaster()
myMaster.Robots = []Robot{
myMaster.Robots = []*Robot{
newTestRobot("Robot 1"),
newTestRobot("Robot 2"),
newTestRobot("Robot 3"),
}
startRobots = func(m *Master) {
for s := range m.Robots {
m.Robots[s].startRobot()
}
trap = func(c chan os.Signal) {
c <- os.Interrupt
}
myMaster.Start()
})
Expand All @@ -29,11 +28,23 @@ var _ = Describe("Master", func() {
It("should Find the specific robot", func() {
Expect(myMaster.FindRobot("Robot 1").Name).To(Equal("Robot 1"))
})
It("should return nil if Robot doesn't exist", func() {
Expect(myMaster.FindRobot("Robot 4")).To(BeNil())
})
It("should Find the specific robot device", func() {
Expect(myMaster.FindRobotDevice("Robot 2", "Device 2").Name).To(Equal("Device 2"))
})
It("should return nil if the robot device doesn't exist", func() {
Expect(myMaster.FindRobotDevice("Robot 4", "Device 2")).To(BeNil())
})
It("should Find the specific robot connection", func() {
Expect(myMaster.FindRobotConnection("Robot 3", "Connection 1").Name).To(Equal("Connection 1"))
})
It("should return nil if the robot connection doesn't exist", func() {
Expect(myMaster.FindRobotConnection("Robot 4", "Connection 1")).To(BeNil())
})
It("Commands should return device commands", func() {
Expect(myMaster.FindRobotDevice("Robot 2", "Device 1").Commands()).To(Equal([]string{"DriverCommand1", "DriverCommand2", "DriverCommand3"}))
})
})
})
43 changes: 19 additions & 24 deletions robot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,35 @@ import (
var _ = Describe("Robot", func() {

var (
someRobot Robot
someRobot *Robot
)

BeforeEach(func() {
someRobot = newTestRobot("")
start = func(r *Robot) {
r.startRobot()
}
someRobot.Start()
})

Context("when valid", func() {
It("initName should not change name when already set", func() {
someRobot.Name = "Bumblebee"
Expect(someRobot.Name).To(Equal("Bumblebee"))
BeforeEach(func() {
someRobot = newTestRobot("")
someRobot.Start()
})
It("initName should set random name when not set", func() {

It("should set random name when not set", func() {
Expect(someRobot.Name).NotTo(BeNil())
Expect(someRobot.Name).NotTo(Equal("Bumblebee"))
})
It("initCommands should set RobotCommands equal to Commands Key", func() {
Expect(someRobot.RobotCommands).To(Equal([]string{"Command1", "Command2"}))
It("GetDevice should return nil if device doesn't exist", func() {
Expect(someRobot.GetDevice("Device 4")).To(BeNil())
})
It("GetDevices should return robot devices", func() {
Expect(someRobot.GetDevices).NotTo(BeNil())
})
It("GetDevice should return a robot device", func() {
It("GetDevice should return device", func() {
Expect(someRobot.GetDevice("Device 1").Name).To(Equal("Device 1"))
})
It("initConnections should initialize connections", func() {
Expect(len(someRobot.connections)).To(Equal(3))
It("GetDevices should return devices", func() {
Expect(len(someRobot.GetDevices())).To(Equal(3))
})
It("GetConnection should return nil if connection doesn't exist", func() {
Expect(someRobot.GetConnection("Connection 4")).To(BeNil())
})
It("GetConnection should return connection", func() {
Expect(someRobot.GetConnection("Connection 1").Name).To(Equal("Connection 1"))
})
It("initDevices should initialize devices", func() {
Expect(len(someRobot.devices)).To(Equal(3))
It("GetConnections should return connections", func() {
Expect(len(someRobot.GetConnections())).To(Equal(3))
})
})
})
10 changes: 8 additions & 2 deletions test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ func newTestDriver(name string) *testDriver {
}
return d
}

func newTestAdaptor(name string) *testAdaptor {
a := new(testAdaptor)
a.Name = name
a.Params = map[string]interface{}{
"param1": "1",
"param2": 2,
}
return a
}

func newTestRobot(name string) Robot {
return Robot{
func newTestRobot(name string) *Robot {
return &Robot{
Name: name,
Connections: []Connection{newTestAdaptor("Connection 1"), newTestAdaptor("Connection 2"), newTestAdaptor("Connection 3")},
Devices: []Device{newTestDriver("Device 1"), newTestDriver("Device 2"), newTestDriver("Device 3")},
Work: func() {},
Commands: map[string]interface{}{
"Command1": func() {},
"Command2": func() {},
Expand Down

0 comments on commit 9875101

Please sign in to comment.