From d6d9e89e96cdbad767ae9228eda1afad46beb96c Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Tue, 31 Dec 2013 13:16:25 -0800 Subject: [PATCH] Clean up tests --- device_test.go | 5 +---- master_test.go | 30 +++++++++--------------------- robot_test.go | 9 +-------- test_helper.go | 12 ++++++++++++ 4 files changed, 23 insertions(+), 33 deletions(-) diff --git a/device_test.go b/device_test.go index b4a77db91..d90526387 100644 --- a/device_test.go +++ b/device_test.go @@ -12,10 +12,7 @@ var _ = Describe("Device", func() { ) BeforeEach(func() { - someRobot = Robot{ - Connections: []Connection{newTestAdaptor("Connection 1")}, - Devices: []Device{newTestDriver("Device 1")}, - } + someRobot = newTestRobot("") }) Context("when valid", func() { diff --git a/master_test.go b/master_test.go index 483797340..914889dc6 100644 --- a/master_test.go +++ b/master_test.go @@ -8,31 +8,19 @@ import ( var _ = Describe("Master", func() { var ( - myMaster Master + myMaster *Master ) BeforeEach(func() { - myMaster = Master{ - Robots: []Robot{ - Robot{ - Name: "Robot 1", - Connections: []Connection{newTestAdaptor("Connection 1")}, - Devices: []Device{newTestDriver("Device 1")}, - }, - Robot{ - Name: "Robot 2", - Connections: []Connection{newTestAdaptor("Connection 2")}, - Devices: []Device{newTestDriver("Device 2")}, - }, - Robot{ - Name: "Robot 3", - Connections: []Connection{newTestAdaptor("Connection 3")}, - Devices: []Device{newTestDriver("Device 3")}, - }, - }, + myMaster = GobotMaster() + myMaster.Robots = []Robot{ + newTestRobot("Robot 1"), + newTestRobot("Robot 2"), + newTestRobot("Robot 3"), + } + for s := range myMaster.Robots { + myMaster.Robots[s].startRobot() } - myMaster.Robots[0].initDevices() - myMaster.Robots[0].initConnections() }) Context("when valid", func() { diff --git a/robot_test.go b/robot_test.go index a9c114848..ff91fba7e 100644 --- a/robot_test.go +++ b/robot_test.go @@ -12,14 +12,7 @@ var _ = Describe("Robot", func() { ) BeforeEach(func() { - someRobot = Robot{ - Connections: []Connection{newTestAdaptor("Connection 1"), newTestAdaptor("Connection 2"), newTestAdaptor("Connection 3")}, - Devices: []Device{newTestDriver("Device 1"), newTestDriver("Device 2"), newTestDriver("Device 3")}, - Commands: map[string]interface{}{ - "Command1": func() {}, - "Command2": func() {}, - }, - } + someRobot = newTestRobot("") }) Context("when valid", func() { diff --git a/test_helper.go b/test_helper.go index e2fe1dc02..fefc02f08 100644 --- a/test_helper.go +++ b/test_helper.go @@ -30,3 +30,15 @@ func newTestAdaptor(name string) *testAdaptor { a.Name = name return a } + +func newTestRobot(name string) Robot { + return Robot{ + Name: name, + Connections: []Connection{newTestAdaptor("Connection 1"), newTestAdaptor("Connection 2"), newTestAdaptor("Connection 3")}, + Devices: []Device{newTestDriver("Device 1"), newTestDriver("Device 2"), newTestDriver("Device 3")}, + Commands: map[string]interface{}{ + "Command1": func() {}, + "Command2": func() {}, + }, + } +}