Gobot tests are green again

This commit is contained in:
Adrian Zankich 2014-05-03 03:22:22 -07:00
parent e500296b96
commit 819ec4f709
3 changed files with 32 additions and 72 deletions

View File

@ -6,32 +6,49 @@ import (
"os" "os"
) )
var _ = Describe("Master", func() { var _ = Describe("Gobot", func() {
var ( var (
m *Master g *Gobot
) )
BeforeEach(func() { BeforeEach(func() {
m = NewMaster() g = NewGobot()
m.trap = func(c chan os.Signal) { g.trap = func(c chan os.Signal) {
c <- os.Interrupt c <- os.Interrupt
} }
m.Robots = []*Robot{ g.Robots = []*Robot{
newTestRobot("Robot 1"), newTestRobot("Robot 1"),
newTestRobot("Robot 2"), newTestRobot("Robot 2"),
newTestRobot("Robot 3"), newTestRobot("Robot 3"),
} }
m.Api = NewApi() g.Start()
m.Api.startFunc = func(m *api) {}
m.Start()
}) })
Context("when valid", func() { Context("when valid", func() {
It("should Find the specific robot", func() { It("should Find the specific robot", func() {
Expect(m.FindRobot("Robot 1").Name).To(Equal("Robot 1")) Expect(g.Robot("Robot 1").Name).To(Equal("Robot 1"))
}) })
It("should return nil if Robot doesn't exist", func() { It("should return nil if Robot doesn't exist", func() {
Expect(m.FindRobot("Robot 4")).To(BeNil()) Expect(g.Robot("Robot 4")).To(BeNil())
}) })
It("Device should return nil if device doesn't exist", func() {
Expect(g.Robot("Robot 1").Device("Device 4")).To(BeNil())
})
It("Device should return device", func() {
Expect(g.Robot("Robot 1").Device("Device 1").Name).To(Equal("Device 1"))
})
It("Devices should return devices", func() {
Expect(len(g.Robot("Robot 1").Devices())).To(Equal(3))
})
It("Connection should return nil if connection doesn't exist", func() {
Expect(g.Robot("Robot 1").Connection("Connection 4")).To(BeNil())
})
It("Connection should return connection", func() {
Expect(g.Robot("Robot 1").Connection("Connection 1").Name).To(Equal("Connection 1"))
})
It("Connections should return connections", func() {
Expect(len(g.Robot("Robot 1").Connections())).To(Equal(3))
})
}) })
}) })

View File

@ -1,47 +0,0 @@
package gobot
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"os"
)
var _ = Describe("Robot", func() {
var (
r *Robot
)
Context("when valid", func() {
BeforeEach(func() {
r = newTestRobot("")
r.master = NewMaster()
r.master.trap = func(c chan os.Signal) {
c <- os.Interrupt
}
r.Start()
})
It("should set random name when not set", func() {
Expect(r.Name).NotTo(BeNil())
})
It("GetDevice should return nil if device doesn't exist", func() {
Expect(r.GetDevice("Device 4")).To(BeNil())
})
It("GetDevice should return device", func() {
Expect(r.GetDevice("Device 1").Name).To(Equal("Device 1"))
})
It("GetDevices should return devices", func() {
Expect(len(r.GetDevices())).To(Equal(3))
})
It("GetConnection should return nil if connection doesn't exist", func() {
Expect(r.GetConnection("Connection 4")).To(BeNil())
})
It("GetConnection should return connection", func() {
Expect(r.GetConnection("Connection 1").Name).To(Equal("Connection 1"))
})
It("GetConnections should return connections", func() {
Expect(len(r.GetConnections())).To(Equal(3))
})
})
})

View File

@ -1,11 +1,7 @@
package gobot package gobot
/*
import ( import (
"fmt" "fmt"
. "github.com/hybridgroup/gobot/adaptor"
. "github.com/hybridgroup/gobot/driver"
) )
type testStruct struct { type testStruct struct {
@ -77,15 +73,11 @@ func newTestRobot(name string) *Robot {
driver1 := newTestDriver("Device 1", adaptor1) driver1 := newTestDriver("Device 1", adaptor1)
driver2 := newTestDriver("Device 2", adaptor2) driver2 := newTestDriver("Device 2", adaptor2)
driver3 := newTestDriver("Device 3", adaptor3) driver3 := newTestDriver("Device 3", adaptor3)
return &Robot{ work := func() {}
Name: name, //Commands := map[string]interface{}{
//Connections: []Connection{adaptor1, adaptor2, adaptor3}, // "robotTestFunction": robotTestFunction,
//Devices: []Device{driver1, driver2, driver3}, //}
Work: func() {}, return NewRobot(name, []Connection{adaptor1, adaptor2, adaptor3}, []Device{driver1, driver2, driver3}, work)
Commands: map[string]interface{}{
"robotTestFunction": robotTestFunction,
},
}
} }
func newTestStruct() *testStruct { func newTestStruct() *testStruct {
@ -94,5 +86,3 @@ func newTestStruct() *testStruct {
s.f = 0.2 s.f = 0.2
return s return s
} }
*/