1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00

test: begin splitting tests into separate files for better separation of testing concerns

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-02-25 12:00:32 +01:00
parent 9f838bd0ae
commit 2bba294b2f
2 changed files with 31 additions and 14 deletions

View File

@ -10,16 +10,6 @@ import (
"gobot.io/x/gobot/gobottest"
)
func TestConnectionEach(t *testing.T) {
r := newTestRobot("Robot1")
i := 0
r.Connections().Each(func(conn Connection) {
i++
})
gobottest.Assert(t, r.Connections().Len(), i)
}
func initTestMaster() *Master {
log.SetOutput(&NullReadWriteCloser{})
g := NewMaster()
@ -56,7 +46,7 @@ func TestNullReadWriteCloser(t *testing.T) {
gobottest.Assert(t, n.Close(), nil)
}
func TestGobotRobot(t *testing.T) {
func TestMasterRobot(t *testing.T) {
g := initTestMaster()
gobottest.Assert(t, g.Robot("Robot1").Name, "Robot1")
gobottest.Assert(t, g.Robot("Robot4"), (*Robot)(nil))
@ -69,7 +59,7 @@ func TestGobotRobot(t *testing.T) {
gobottest.Assert(t, g.Robot("Robot1").Connections().Len(), 3)
}
func TestGobotToJSON(t *testing.T) {
func TestMasterToJSON(t *testing.T) {
g := initTestMaster()
g.AddCommand("test_function", func(params map[string]interface{}) interface{} {
return nil
@ -103,7 +93,7 @@ func TestMasterStartDriverErrors(t *testing.T) {
testDriverStart = func() (err error) { return }
}
func TestRobotHaltDriverErrors(t *testing.T) {
func TestMasterHaltFromRobotDriverErrors(t *testing.T) {
g := initTestMaster1Robot()
e := errors.New("driver halt error 1")
testDriverHalt = func() (err error) {
@ -121,7 +111,7 @@ func TestRobotHaltDriverErrors(t *testing.T) {
testDriverHalt = func() (err error) { return }
}
func TestMasterStartAdaptorErrors(t *testing.T) {
func TestMasterStartRobotAdaptorErrors(t *testing.T) {
g := initTestMaster1Robot()
e := errors.New("adaptor start error 1")

27
robot_test.go Normal file
View File

@ -0,0 +1,27 @@
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()))
}