forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gobot_test.go
45 lines (40 loc) · 1.11 KB
/
gobot_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gobot
import (
"log"
"os"
"testing"
)
func initTestGobot() *Gobot {
log.SetOutput(&NullReadWriteCloser{})
g := NewGobot()
g.trap = func(c chan os.Signal) {
c <- os.Interrupt
}
g.AddRobot(NewTestRobot("Robot 1"))
g.AddRobot(NewTestRobot("Robot 2"))
g.AddRobot(NewTestRobot("Robot 3"))
return g
}
func TestGobotStart(t *testing.T) {
g := initTestGobot()
g.Start()
}
func TestGobotRobot(t *testing.T) {
g := initTestGobot()
Expect(t, g.Robot("Robot 1").Name, "Robot 1")
Expect(t, g.Robot("Robot 4"), (*Robot)(nil))
Expect(t, g.Robot("Robot 1").Device("Device 4"), (Device)(nil))
Expect(t, g.Robot("Robot 1").Device("Device 1").Name(), "Device 1")
Expect(t, g.Robot("Robot 1").Devices().Len(), 3)
Expect(t, g.Robot("Robot 1").Connection("Connection 4"), (Connection)(nil))
Expect(t, g.Robot("Robot 1").Connections().Len(), 3)
}
func TestGobotToJSON(t *testing.T) {
g := initTestGobot()
g.AddCommand("test_function", func(params map[string]interface{}) interface{} {
return nil
})
json := g.ToJSON()
Expect(t, len(json.Robots), g.Robots().Len())
Expect(t, len(json.Commands), len(g.Commands()))
}