2013-12-30 16:51:21 -08:00
|
|
|
package gobot
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2014-04-26 09:24:43 -07:00
|
|
|
"os"
|
2013-12-30 16:51:21 -08:00
|
|
|
)
|
|
|
|
|
2014-05-03 03:22:22 -07:00
|
|
|
var _ = Describe("Gobot", func() {
|
2013-12-30 16:51:21 -08:00
|
|
|
var (
|
2014-05-03 03:22:22 -07:00
|
|
|
g *Gobot
|
2013-12-30 16:51:21 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2014-05-03 03:22:22 -07:00
|
|
|
g = NewGobot()
|
|
|
|
g.trap = func(c chan os.Signal) {
|
2014-04-26 10:13:33 -06:00
|
|
|
c <- os.Interrupt
|
|
|
|
}
|
2014-05-03 03:22:22 -07:00
|
|
|
g.Robots = []*Robot{
|
2013-12-31 13:16:25 -08:00
|
|
|
newTestRobot("Robot 1"),
|
|
|
|
newTestRobot("Robot 2"),
|
|
|
|
newTestRobot("Robot 3"),
|
|
|
|
}
|
2014-05-03 03:22:22 -07:00
|
|
|
g.Start()
|
2013-12-30 16:51:21 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
Context("when valid", func() {
|
|
|
|
It("should Find the specific robot", func() {
|
2014-05-03 03:22:22 -07:00
|
|
|
Expect(g.Robot("Robot 1").Name).To(Equal("Robot 1"))
|
2013-12-30 16:51:21 -08:00
|
|
|
})
|
2014-04-14 23:16:35 -07:00
|
|
|
It("should return nil if Robot doesn't exist", func() {
|
2014-05-03 03:22:22 -07:00
|
|
|
Expect(g.Robot("Robot 4")).To(BeNil())
|
2014-04-14 23:16:35 -07:00
|
|
|
})
|
2014-05-03 03:22:22 -07:00
|
|
|
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))
|
|
|
|
})
|
|
|
|
|
2013-12-30 16:51:21 -08:00
|
|
|
})
|
|
|
|
})
|