From 2bba294b2f3fb8ad32c2f239f8ab0aff2f24659e Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sat, 25 Feb 2017 12:00:32 +0100 Subject: [PATCH] test: begin splitting tests into separate files for better separation of testing concerns Signed-off-by: deadprogram --- master_test.go | 18 ++++-------------- robot_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 robot_test.go diff --git a/master_test.go b/master_test.go index daaa1178a..f83bf977d 100644 --- a/master_test.go +++ b/master_test.go @@ -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") diff --git a/robot_test.go b/robot_test.go new file mode 100644 index 000000000..88edb78b9 --- /dev/null +++ b/robot_test.go @@ -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())) +}