hybridgroup.gobot/gobot_test.go

55 lines
1.4 KiB
Go
Raw Normal View History

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