diff --git a/gobot_test.go b/gobot_test.go index 382feb22..9b0bf7c9 100644 --- a/gobot_test.go +++ b/gobot_test.go @@ -6,32 +6,49 @@ import ( "os" ) -var _ = Describe("Master", func() { +var _ = Describe("Gobot", func() { var ( - m *Master + g *Gobot ) BeforeEach(func() { - m = NewMaster() - m.trap = func(c chan os.Signal) { + g = NewGobot() + g.trap = func(c chan os.Signal) { c <- os.Interrupt } - m.Robots = []*Robot{ + g.Robots = []*Robot{ newTestRobot("Robot 1"), newTestRobot("Robot 2"), newTestRobot("Robot 3"), } - m.Api = NewApi() - m.Api.startFunc = func(m *api) {} - m.Start() + g.Start() }) Context("when valid", func() { It("should Find the specific robot", func() { - Expect(m.FindRobot("Robot 1").Name).To(Equal("Robot 1")) + Expect(g.Robot("Robot 1").Name).To(Equal("Robot 1")) }) It("should return nil if Robot doesn't exist", func() { - Expect(m.FindRobot("Robot 4")).To(BeNil()) + Expect(g.Robot("Robot 4")).To(BeNil()) }) + It("Device should return nil if device doesn't exist", func() { + Expect(g.Robot("Robot 1").Device("Device 4")).To(BeNil()) + }) + It("Device should return device", func() { + Expect(g.Robot("Robot 1").Device("Device 1").Name).To(Equal("Device 1")) + }) + It("Devices should return devices", func() { + Expect(len(g.Robot("Robot 1").Devices())).To(Equal(3)) + }) + It("Connection should return nil if connection doesn't exist", func() { + Expect(g.Robot("Robot 1").Connection("Connection 4")).To(BeNil()) + }) + It("Connection should return connection", func() { + Expect(g.Robot("Robot 1").Connection("Connection 1").Name).To(Equal("Connection 1")) + }) + It("Connections should return connections", func() { + Expect(len(g.Robot("Robot 1").Connections())).To(Equal(3)) + }) + }) }) diff --git a/robot_test.go b/robot_test.go deleted file mode 100644 index 866cf0c4..00000000 --- a/robot_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package gobot - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "os" -) - -var _ = Describe("Robot", func() { - - var ( - r *Robot - ) - - Context("when valid", func() { - BeforeEach(func() { - r = newTestRobot("") - r.master = NewMaster() - r.master.trap = func(c chan os.Signal) { - c <- os.Interrupt - } - r.Start() - }) - - It("should set random name when not set", func() { - Expect(r.Name).NotTo(BeNil()) - }) - It("GetDevice should return nil if device doesn't exist", func() { - Expect(r.GetDevice("Device 4")).To(BeNil()) - }) - It("GetDevice should return device", func() { - Expect(r.GetDevice("Device 1").Name).To(Equal("Device 1")) - }) - It("GetDevices should return devices", func() { - Expect(len(r.GetDevices())).To(Equal(3)) - }) - It("GetConnection should return nil if connection doesn't exist", func() { - Expect(r.GetConnection("Connection 4")).To(BeNil()) - }) - It("GetConnection should return connection", func() { - Expect(r.GetConnection("Connection 1").Name).To(Equal("Connection 1")) - }) - It("GetConnections should return connections", func() { - Expect(len(r.GetConnections())).To(Equal(3)) - }) - }) -}) diff --git a/test_helper.go b/test_helper.go index 851f475e..38d44375 100644 --- a/test_helper.go +++ b/test_helper.go @@ -1,11 +1,7 @@ package gobot -/* - import ( "fmt" - . "github.com/hybridgroup/gobot/adaptor" - . "github.com/hybridgroup/gobot/driver" ) type testStruct struct { @@ -77,15 +73,11 @@ func newTestRobot(name string) *Robot { driver1 := newTestDriver("Device 1", adaptor1) driver2 := newTestDriver("Device 2", adaptor2) driver3 := newTestDriver("Device 3", adaptor3) - return &Robot{ - Name: name, - //Connections: []Connection{adaptor1, adaptor2, adaptor3}, - //Devices: []Device{driver1, driver2, driver3}, - Work: func() {}, - Commands: map[string]interface{}{ - "robotTestFunction": robotTestFunction, - }, - } + work := func() {} + //Commands := map[string]interface{}{ + // "robotTestFunction": robotTestFunction, + //} + return NewRobot(name, []Connection{adaptor1, adaptor2, adaptor3}, []Device{driver1, driver2, driver3}, work) } func newTestStruct() *testStruct { @@ -94,5 +86,3 @@ func newTestStruct() *testStruct { s.f = 0.2 return s } - -*/