hybridgroup.gobot/robot_test.go

47 lines
1.2 KiB
Go
Raw Normal View History

2013-12-02 14:16:02 +08:00
package gobot
import (
2013-12-03 09:10:36 +08:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
2014-04-16 08:59:44 +08:00
"os"
2013-12-02 14:16:02 +08:00
)
var _ = Describe("Robot", func() {
2013-12-03 09:10:36 +08:00
var (
2014-04-15 14:16:35 +08:00
someRobot *Robot
2013-12-03 09:10:36 +08:00
)
2013-12-02 14:16:02 +08:00
2013-12-03 09:10:36 +08:00
Context("when valid", func() {
2014-04-15 14:16:35 +08:00
BeforeEach(func() {
someRobot = newTestRobot("")
2014-04-16 08:59:44 +08:00
trap = func(c chan os.Signal) {
c <- os.Interrupt
}
2014-04-15 14:16:35 +08:00
someRobot.Start()
2013-12-03 09:10:36 +08:00
})
2014-04-15 14:16:35 +08:00
It("should set random name when not set", func() {
2013-12-03 09:10:36 +08:00
Expect(someRobot.Name).NotTo(BeNil())
})
2014-04-15 14:16:35 +08:00
It("GetDevice should return nil if device doesn't exist", func() {
Expect(someRobot.GetDevice("Device 4")).To(BeNil())
2013-12-03 09:10:36 +08:00
})
2014-04-15 14:16:35 +08:00
It("GetDevice should return device", func() {
2013-12-31 08:51:21 +08:00
Expect(someRobot.GetDevice("Device 1").Name).To(Equal("Device 1"))
2013-12-03 09:10:36 +08:00
})
2014-04-15 14:16:35 +08:00
It("GetDevices should return devices", func() {
Expect(len(someRobot.GetDevices())).To(Equal(3))
})
It("GetConnection should return nil if connection doesn't exist", func() {
Expect(someRobot.GetConnection("Connection 4")).To(BeNil())
})
It("GetConnection should return connection", func() {
Expect(someRobot.GetConnection("Connection 1").Name).To(Equal("Connection 1"))
2013-12-03 09:10:36 +08:00
})
2014-04-15 14:16:35 +08:00
It("GetConnections should return connections", func() {
Expect(len(someRobot.GetConnections())).To(Equal(3))
2013-12-03 09:10:36 +08:00
})
})
2013-12-02 14:16:02 +08:00
})