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

46 lines
1.1 KiB
Go
Raw Normal View History

2013-12-30 16:51:21 -08:00
package gobot
import (
2014-06-12 14:38:03 -07:00
"log"
2014-04-26 09:24:43 -07:00
"os"
2014-06-12 14:38:03 -07:00
"testing"
2013-12-30 16:51:21 -08:00
)
2014-06-13 16:01:39 -07:00
func initTestGobot() *Gobot {
log.SetOutput(&NullReadWriteCloser{})
g := NewGobot()
2014-06-12 14:38:03 -07:00
g.trap = func(c chan os.Signal) {
c <- os.Interrupt
}
2014-07-21 22:19:04 -07:00
g.AddRobot(NewTestRobot("Robot1"))
g.AddRobot(NewTestRobot("Robot2"))
g.AddRobot(NewTestRobot("Robot3"))
2014-06-13 16:01:39 -07:00
return g
2014-06-12 14:38:03 -07:00
}
2013-12-30 16:51:21 -08:00
2014-06-13 16:01:39 -07:00
func TestGobotStart(t *testing.T) {
g := initTestGobot()
2014-06-12 14:38:03 -07:00
g.Start()
}
2014-05-03 03:22:22 -07:00
2014-06-13 16:01:39 -07:00
func TestGobotRobot(t *testing.T) {
g := initTestGobot()
2014-07-21 22:19:04 -07:00
Assert(t, g.Robot("Robot1").Name, "Robot1")
Assert(t, g.Robot("Robot4"), (*Robot)(nil))
Assert(t, g.Robot("Robot1").Device("Device4"), (Device)(nil))
Assert(t, g.Robot("Robot1").Device("Device1").Name(), "Device1")
Assert(t, g.Robot("Robot1").Devices().Len(), 3)
Assert(t, g.Robot("Robot1").Connection("Connection4"), (Connection)(nil))
Assert(t, g.Robot("Robot1").Connections().Len(), 3)
2014-06-12 14:38:03 -07:00
}
2014-07-10 11:14:08 -07:00
func TestGobotToJSON(t *testing.T) {
g := initTestGobot()
g.AddCommand("test_function", func(params map[string]interface{}) interface{} {
return nil
})
json := g.ToJSON()
Assert(t, len(json.Robots), g.Robots().Len())
Assert(t, len(json.Commands), len(g.Commands()))
2014-07-10 11:14:08 -07:00
}