1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/master_test.go

52 lines
1.5 KiB
Go
Raw Normal View History

2013-12-30 16:51:21 -08:00
package gobot
import (
2014-04-26 10:13:33 -06:00
"os"
2013-12-30 16:51:21 -08:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Master", func() {
var (
2013-12-31 13:16:25 -08:00
myMaster *Master
2013-12-30 16:51:21 -08:00
)
BeforeEach(func() {
2014-04-26 10:13:33 -06:00
myMaster = NewMaster()
myMaster.trap = func(c chan os.Signal) {
c <- os.Interrupt
}
2014-04-14 23:16:35 -07:00
myMaster.Robots = []*Robot{
2013-12-31 13:16:25 -08:00
newTestRobot("Robot 1"),
newTestRobot("Robot 2"),
newTestRobot("Robot 3"),
}
2014-04-18 14:45:50 -07:00
startApi = func(m *api) {}
2014-04-11 06:02:21 -07:00
myMaster.Start()
2013-12-30 16:51:21 -08:00
})
Context("when valid", func() {
It("should Find the specific robot", func() {
Expect(myMaster.FindRobot("Robot 1").Name).To(Equal("Robot 1"))
})
2014-04-14 23:16:35 -07:00
It("should return nil if Robot doesn't exist", func() {
Expect(myMaster.FindRobot("Robot 4")).To(BeNil())
})
2013-12-30 16:51:21 -08:00
It("should Find the specific robot device", func() {
2014-01-02 15:12:41 -08:00
Expect(myMaster.FindRobotDevice("Robot 2", "Device 2").Name).To(Equal("Device 2"))
2013-12-30 16:51:21 -08:00
})
2014-04-14 23:16:35 -07:00
It("should return nil if the robot device doesn't exist", func() {
Expect(myMaster.FindRobotDevice("Robot 4", "Device 2")).To(BeNil())
})
2013-12-30 16:51:21 -08:00
It("should Find the specific robot connection", func() {
2014-01-02 15:12:41 -08:00
Expect(myMaster.FindRobotConnection("Robot 3", "Connection 1").Name).To(Equal("Connection 1"))
2013-12-30 16:51:21 -08:00
})
2014-04-14 23:16:35 -07:00
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() {
2014-04-15 19:19:14 -07:00
Expect(myMaster.FindRobotDevice("Robot 2", "Device 1").Commands()).To(Equal([]string{"TestDriverCommand", "DriverCommand"}))
2014-04-14 23:16:35 -07:00
})
2013-12-30 16:51:21 -08:00
})
})