forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot_test.go
37 lines (31 loc) · 969 Bytes
/
robot_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
package gobot
import (
"testing"
"gobot.io/x/gobot/gobottest"
)
func TestRobotConnectionEach(t *testing.T) {
r := newTestRobot("Robot1")
i := 0
r.Connections().Each(func(conn Connection) {
i++
})
gobottest.Assert(t, r.Connections().Len(), i)
}
func TestRobotToJSON(t *testing.T) {
r := newTestRobot("Robot99")
r.AddCommand("test_function", func(params map[string]interface{}) interface{} {
return nil
})
json := NewJSONRobot(r)
gobottest.Assert(t, len(json.Devices), r.Devices().Len())
gobottest.Assert(t, len(json.Commands), len(r.Commands()))
}
func TestRobotDevicesToJSON(t *testing.T) {
r := newTestRobot("Robot99")
json := NewJSONRobot(r)
gobottest.Assert(t, len(json.Devices), r.Devices().Len())
gobottest.Assert(t, json.Devices[0].Name, "Device1")
gobottest.Assert(t, json.Devices[0].Driver, "*gobot.testDriver")
gobottest.Assert(t, json.Devices[0].Connection, "Connection1")
gobottest.Assert(t, len(json.Devices[0].Commands), 1)
}