Skip to content

Commit

Permalink
test: begin splitting tests into separate files for better separation…
Browse files Browse the repository at this point in the history
… of testing concerns

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Feb 25, 2017
1 parent 9f838bd commit 2bba294
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
18 changes: 4 additions & 14 deletions master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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")

Expand Down
27 changes: 27 additions & 0 deletions robot_test.go
Original file line number Diff line number Diff line change
@@ -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()))
}

0 comments on commit 2bba294

Please sign in to comment.