Skip to content

Commit

Permalink
Make travis happy
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jul 15, 2015
1 parent c3bc235 commit a8fa365
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
language: go
sudo: true
go:
- 1.2
- 1.3
- 1.4
- release
- tip
matrix:
allow_failures:
- go: tip
before_install:
- sudo add-apt-repository -y ppa:kubuntu-ppa/backports
- sudo add-apt-repository -y ppa:zoogie/sdl2-snapshots
Expand Down
22 changes: 12 additions & 10 deletions platforms/firmata/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,29 @@ func TestProcess(t *testing.T) {
func TestConnect(t *testing.T) {
b := New()

testReadData = testProtocolResponse()
response := testProtocolResponse()

go func() {
for {
testReadData = append(testReadData, response...)
<-time.After(100 * time.Millisecond)
}
}()

gobot.Once(b.Event("ProtocolVersion"), func(data interface{}) {
<-time.After(1 * time.Millisecond)
testReadData = testFirmwareResponse()
response = testFirmwareResponse()
})

gobot.Once(b.Event("FirmwareQuery"), func(data interface{}) {
<-time.After(1 * time.Millisecond)
testReadData = testCapabilitiesResponse()
response = testCapabilitiesResponse()
})

gobot.Once(b.Event("CapabilityQuery"), func(data interface{}) {
<-time.After(1 * time.Millisecond)
testReadData = testAnalogMappingResponse()
response = testAnalogMappingResponse()
})

gobot.Once(b.Event("AnalogMappingQuery"), func(data interface{}) {

<-time.After(1 * time.Millisecond)
testReadData = testProtocolResponse()
response = testProtocolResponse()
})

gobot.Assert(t, b.Connect(readWriteCloser{}), nil)
Expand Down
13 changes: 10 additions & 3 deletions platforms/gpio/analog_sensor_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ func TestAnalogSensorDriverStart(t *testing.T) {

d := NewAnalogSensorDriver(newGpioTestAdaptor("adaptor"), "bot", "1")

testAdaptorAnalogRead = func() (val int, err error) {
val = 0
return
}
gobot.Assert(t, len(d.Start()), 0)

// data was received
gobot.Once(d.Event(Data), func(data interface{}) {
gobot.Assert(t, data.(int), 100)
sem <- true
Expand All @@ -45,10 +50,11 @@ func TestAnalogSensorDriverStart(t *testing.T) {

select {
case <-sem:
case <-time.After(15 * time.Millisecond):
case <-time.After(10 * time.Second):
t.Errorf("AnalogSensor Event \"Data\" was not published")
}

// read error
gobot.Once(d.Event(Error), func(data interface{}) {
gobot.Assert(t, data.(error).Error(), "read error")
sem <- true
Expand All @@ -61,10 +67,11 @@ func TestAnalogSensorDriverStart(t *testing.T) {

select {
case <-sem:
case <-time.After(15 * time.Millisecond):
case <-time.After(10 * time.Second):
t.Errorf("AnalogSensor Event \"Error\" was not published")
}

// send a halt message
gobot.Once(d.Event(Data), func(data interface{}) {
sem <- true
})
Expand All @@ -79,7 +86,7 @@ func TestAnalogSensorDriverStart(t *testing.T) {
select {
case <-sem:
t.Errorf("AnalogSensor Event should not published")
case <-time.After(30 * time.Millisecond):
case <-time.After(100 * time.Millisecond):
}
}

Expand Down
73 changes: 53 additions & 20 deletions platforms/i2c/wiichuck_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,29 @@ func TestWiichuckDriverUpdate(t *testing.T) {
gobot.Assert(t, data, true)
chann <- true
})
<-chann

chann = make(chan bool)
wii.update(decryptedValue)

select {
case <-chann:
case <-time.After(10 * time.Second):
t.Errorf("Did not recieve 'C' event")
}

gobot.On(wii.Event(Z), func(data interface{}) {
gobot.Assert(t, data, true)
chann <- true
})
<-chann

// - This should be done by WiichuckDriver.updateJoystick
chann = make(chan bool)
wii.update(decryptedValue)

select {
case <-chann:
case <-time.After(10 * time.Second):
t.Errorf("Did not recieve 'Z' event")
}

// - This should be done by WiichuckDriver.updateJoystick
expectedData := map[string]float64{
"x": float64(0),
"y": float64(0),
Expand All @@ -123,7 +131,14 @@ func TestWiichuckDriverUpdate(t *testing.T) {
gobot.Assert(t, data, expectedData)
chann <- true
})
<-chann

wii.update(decryptedValue)

select {
case <-chann:
case <-time.After(10 * time.Second):
t.Errorf("Did not recieve 'Joystick' event")
}

// ------ When value is encrypted
wii = initTestWiichuckDriver()
Expand Down Expand Up @@ -249,27 +264,36 @@ func TestWiichuckDriverUpdateButtons(t *testing.T) {

wii.data["c"] = 0

wii.updateButtons()

gobot.On(wii.Event(C), func(data interface{}) {
gobot.Assert(t, true, data)
chann <- true
})
<-chann

wii.updateButtons()

select {
case <-chann:
case <-time.After(10 * time.Second):
t.Errorf("Did not recieve 'C' event")
}

//when data["z"] is 0
chann = make(chan bool)
wii = initTestWiichuckDriver()

wii.data["z"] = 0

wii.updateButtons()

gobot.On(wii.Event(Z), func(data interface{}) {
gobot.Assert(t, true, data)
chann <- true
})
<-chann

wii.updateButtons()

select {
case <-chann:
case <-time.After(10 * time.Second):
t.Errorf("Did not recieve 'Z' event")
}
}

func TestWiichuckDriverUpdateJoystick(t *testing.T) {
Expand All @@ -282,8 +306,6 @@ func TestWiichuckDriverUpdateJoystick(t *testing.T) {
wii.joystick["sx_origin"] = 1
wii.joystick["sy_origin"] = 5

wii.updateJoystick()

expectedData := map[string]float64{
"x": float64(39),
"y": float64(50),
Expand All @@ -293,19 +315,23 @@ func TestWiichuckDriverUpdateJoystick(t *testing.T) {
gobot.Assert(t, data, expectedData)
chann <- true
})
<-chann

wii.updateJoystick()

select {
case <-chann:
case <-time.After(10 * time.Second):
t.Errorf("Did not recieve 'Joystick' event")
}

//// Second pass
chann = make(chan bool)
wii = initTestWiichuckDriver()

wii.data["sx"] = 178
wii.data["sy"] = 34
wii.joystick["sx_origin"] = 14
wii.joystick["sy_origin"] = 27

wii.updateJoystick()

expectedData = map[string]float64{
"x": float64(164),
"y": float64(7),
Expand All @@ -315,5 +341,12 @@ func TestWiichuckDriverUpdateJoystick(t *testing.T) {
gobot.Assert(t, data, expectedData)
chann <- true
})
<-chann

wii.updateJoystick()

select {
case <-chann:
case <-time.After(10 * time.Second):
t.Errorf("Did not recieve 'Joystick' event")
}
}
42 changes: 27 additions & 15 deletions platforms/joystick/joystick_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,53 +41,65 @@ func TestJoystickDriverHandleEvent(t *testing.T) {
sem := make(chan bool)
d := initTestJoystickDriver()
d.Start()

// left x stick
gobot.On(d.Event("left_x"), func(data interface{}) {
gobot.Assert(t, int16(100), data.(int16))
sem <- true
})
d.handleEvent(&sdl.JoyAxisEvent{
Which: 0,
Axis: 0,
Value: 100,
})
gobot.On(d.Event("left_x"), func(data interface{}) {
gobot.Assert(t, int16(100), data.(int16))
select {
case <-sem:
case <-time.After(10 * time.Second):
t.Errorf("Button Event \"left_x\" was not published")
}

// x button press
gobot.On(d.Event("x_press"), func(data interface{}) {
sem <- true
})
<-sem
d.handleEvent(&sdl.JoyButtonEvent{
Which: 0,
Button: 2,
State: 1,
})
gobot.On(d.Event("x_press"), func(data interface{}) {
sem <- true
})
select {
case <-sem:
case <-time.After(10 * time.Millisecond):
case <-time.After(10 * time.Second):
t.Errorf("Button Event \"x_press\" was not published")
}

// x button release
gobot.On(d.Event("x_release"), func(data interface{}) {
sem <- true
})
d.handleEvent(&sdl.JoyButtonEvent{
Which: 0,
Button: 2,
State: 0,
})
gobot.On(d.Event("x_release"), func(data interface{}) {
sem <- true
})
select {
case <-sem:
case <-time.After(10 * time.Millisecond):
case <-time.After(10 * time.Second):
t.Errorf("Button Event \"x_release\" was not published")
}

// down button press
gobot.On(d.Event("down"), func(data interface{}) {
sem <- true
})
d.handleEvent(&sdl.JoyHatEvent{
Which: 0,
Hat: 0,
Value: 4,
})
gobot.On(d.Event("down"), func(data interface{}) {
sem <- true
})
select {
case <-sem:
case <-time.After(10 * time.Millisecond):
case <-time.After(10 * time.Second):
t.Errorf("Hat Event \"down\" was not published")
}

Expand Down
21 changes: 16 additions & 5 deletions platforms/spark/spark_core_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http/httptest"
"net/url"
"testing"
"time"

"github.com/donovanhide/eventsource"
"github.com/hybridgroup/gobot"
Expand Down Expand Up @@ -378,8 +379,7 @@ func TestSparkCoreAdaptorEventStream(t *testing.T) {
stream, err := a.EventStream("devices", "")
gobot.Assert(t, err, nil)

eventChan <- testEventSource{event: "event", data: "sse event"}

// stream message
gobot.Once(stream, func(data interface{}) {
e := data.(Event)
gobot.Assert(t, e.Name, "event")
Expand All @@ -388,10 +388,15 @@ func TestSparkCoreAdaptorEventStream(t *testing.T) {
sem <- true
})

<-sem
eventChan <- testEventSource{event: "event", data: "sse event"}

errorChan <- errors.New("stream error")
select {
case <-sem:
case <-time.After(1 * time.Second):
t.Errorf("Did not recieve stream")
}

// stream error
gobot.Once(stream, func(data interface{}) {
e := data.(Event)
gobot.Assert(t, e.Name, "")
Expand All @@ -400,6 +405,12 @@ func TestSparkCoreAdaptorEventStream(t *testing.T) {
sem <- true
})

<-sem
errorChan <- errors.New("stream error")

select {
case <-sem:
case <-time.After(1 * time.Second):
t.Errorf("Did not recieve stream error")
}

}

0 comments on commit a8fa365

Please sign in to comment.