2013-12-31 08:51:21 +08:00
|
|
|
package gobot
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2014-04-15 14:16:35 +08:00
|
|
|
"os"
|
2013-12-31 08:51:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Master", func() {
|
|
|
|
var (
|
2014-01-01 05:16:25 +08:00
|
|
|
myMaster *Master
|
2013-12-31 08:51:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2014-01-01 05:16:25 +08:00
|
|
|
myMaster = GobotMaster()
|
2014-04-15 14:16:35 +08:00
|
|
|
myMaster.Robots = []*Robot{
|
2014-01-01 05:16:25 +08:00
|
|
|
newTestRobot("Robot 1"),
|
|
|
|
newTestRobot("Robot 2"),
|
|
|
|
newTestRobot("Robot 3"),
|
|
|
|
}
|
2014-04-15 14:16:35 +08:00
|
|
|
trap = func(c chan os.Signal) {
|
|
|
|
c <- os.Interrupt
|
2013-12-31 08:51:21 +08:00
|
|
|
}
|
2014-04-11 21:02:21 +08:00
|
|
|
myMaster.Start()
|
2013-12-31 08: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-15 14:16:35 +08:00
|
|
|
It("should return nil if Robot doesn't exist", func() {
|
|
|
|
Expect(myMaster.FindRobot("Robot 4")).To(BeNil())
|
|
|
|
})
|
2013-12-31 08:51:21 +08:00
|
|
|
It("should Find the specific robot device", func() {
|
2014-01-03 07:12:41 +08:00
|
|
|
Expect(myMaster.FindRobotDevice("Robot 2", "Device 2").Name).To(Equal("Device 2"))
|
2013-12-31 08:51:21 +08:00
|
|
|
})
|
2014-04-15 14:16:35 +08:00
|
|
|
It("should return nil if the robot device doesn't exist", func() {
|
|
|
|
Expect(myMaster.FindRobotDevice("Robot 4", "Device 2")).To(BeNil())
|
|
|
|
})
|
2013-12-31 08:51:21 +08:00
|
|
|
It("should Find the specific robot connection", func() {
|
2014-01-03 07:12:41 +08:00
|
|
|
Expect(myMaster.FindRobotConnection("Robot 3", "Connection 1").Name).To(Equal("Connection 1"))
|
2013-12-31 08:51:21 +08:00
|
|
|
})
|
2014-04-15 14:16:35 +08: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() {
|
|
|
|
Expect(myMaster.FindRobotDevice("Robot 2", "Device 1").Commands()).To(Equal([]string{"DriverCommand1", "DriverCommand2", "DriverCommand3"}))
|
|
|
|
})
|
2013-12-31 08:51:21 +08:00
|
|
|
})
|
|
|
|
})
|