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

66 lines
1.9 KiB
Go
Raw Normal View History

2013-12-01 22:16:02 -08:00
package gobot
import (
2013-12-02 17:10:36 -08:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
2013-12-01 22:16:02 -08:00
)
var _ = Describe("Robot", func() {
2013-12-02 17:10:36 -08:00
var (
someRobot Robot
)
2013-12-01 22:16:02 -08:00
2013-12-02 17:10:36 -08:00
BeforeEach(func() {
someRobot = Robot{
2013-12-30 16:51:21 -08:00
Connections: []Connection{newTestAdaptor("Connection 1"), newTestAdaptor("Connection 2"), newTestAdaptor("Connection 3")},
Devices: []Device{newTestDriver("Device 1"), newTestDriver("Device 2"), newTestDriver("Device 3")},
Commands: map[string]interface{}{
"Command1": func() {},
"Command2": func() {},
2013-12-02 17:10:36 -08:00
},
}
})
2013-12-01 22:16:02 -08:00
2013-12-02 17:10:36 -08:00
Context("when valid", func() {
It("initName should not change name when already set", func() {
someRobot.Name = "Bumblebee"
someRobot.initName()
Expect(someRobot.Name).To(Equal("Bumblebee"))
})
It("initName should set random name when not set", func() {
someRobot.initName()
Expect(someRobot.Name).NotTo(BeNil())
Expect(someRobot.Name).NotTo(Equal("Bumblebee"))
})
2013-12-30 16:51:21 -08:00
It("initCommands should set RobotCommands equal to Commands Key", func() {
someRobot.initCommands()
Expect(someRobot.RobotCommands).To(Equal([]string{"Command1", "Command2"}))
2013-12-02 17:10:36 -08:00
})
2013-12-30 16:51:21 -08:00
It("GetDevices should return robot devices", func() {
someRobot.initDevices()
Expect(someRobot.GetDevices).NotTo(BeNil())
2013-12-02 17:10:36 -08:00
})
2013-12-30 16:51:21 -08:00
It("GetDevice should return a robot device", func() {
someRobot.initDevices()
Expect(someRobot.GetDevice("Device 1").Name).To(Equal("Device 1"))
2013-12-02 17:10:36 -08:00
})
2013-12-30 16:51:21 -08:00
It("initConnections should initialize connections", func() {
someRobot.initConnections()
Expect(len(someRobot.connections)).To(Equal(3))
2013-12-02 17:10:36 -08:00
})
2013-12-30 16:51:21 -08:00
It("initDevices should initialize devices", func() {
someRobot.initDevices()
Expect(len(someRobot.devices)).To(Equal(3))
2013-12-02 17:10:36 -08:00
})
2013-12-30 16:51:21 -08:00
It("startConnections should connect all connections", func() {
someRobot.initConnections()
Expect(someRobot.startConnections()).To(Equal(true))
2013-12-02 17:10:36 -08:00
})
2013-12-30 16:51:21 -08:00
It("startDevices should start all devices", func() {
someRobot.initDevices()
Expect(someRobot.startDevices()).To(Equal(true))
2013-12-02 17:10:36 -08:00
})
})
2013-12-01 22:16:02 -08:00
})