diff --git a/connection_test.go b/connection_test.go deleted file mode 100644 index f1083743..00000000 --- a/connection_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package gobot - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("Connection", func() { - - var ( - someRobot Robot - ) - - BeforeEach(func() { - someRobot = newTestRobot("") - start = func(r *Robot) { - r.startRobot() - } - someRobot.Start() - }) - - Context("when valid", func() { - It("Connect should call adaptor Connect", func() { - Expect(someRobot.Connections[0].Connect()).To(Equal(true)) - }) - It("Finalize should call adaptor Finalize", func() { - Expect(someRobot.Connections[0].Connect()).To(Equal(true)) - }) - It("Disconnect should call adaptor Disconnect", func() { - Expect(someRobot.Connections[0].Connect()).To(Equal(true)) - }) - It("Reconnect should call adaptor Reconnect", func() { - Expect(someRobot.Connections[0].Connect()).To(Equal(true)) - }) - }) -}) diff --git a/device_test.go b/device_test.go deleted file mode 100644 index 7396ba4a..00000000 --- a/device_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package gobot - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("Device", func() { - - var ( - someRobot Robot - ) - - BeforeEach(func() { - someRobot = newTestRobot("") - start = func(r *Robot) { - r.startRobot() - } - someRobot.Start() - }) - - Context("when valid", func() { - It("Commands should return device commands", func() { - Expect(someRobot.devices[0].Commands()).To(Equal([]string{"DriverCommand1", "DriverCommand2", "DriverCommand3"})) - }) - It("Start should call driver start", func() { - Expect(someRobot.Devices[0].Start()).To(Equal(true)) - }) - }) -}) diff --git a/master_test.go b/master_test.go index 86b9865b..25c6d752 100644 --- a/master_test.go +++ b/master_test.go @@ -3,6 +3,7 @@ package gobot import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "os" ) var _ = Describe("Master", func() { @@ -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() }) @@ -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"})) + }) }) }) diff --git a/robot_test.go b/robot_test.go index efebe773..643c64d4 100644 --- a/robot_test.go +++ b/robot_test.go @@ -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("initDevices should initialize devices", func() { - Expect(len(someRobot.devices)).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("GetConnections should return connections", func() { + Expect(len(someRobot.GetConnections())).To(Equal(3)) }) }) }) diff --git a/test_helper.go b/test_helper.go index ad9c3475..643e96da 100644 --- a/test_helper.go +++ b/test_helper.go @@ -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() {},