1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00
hybridgroup.gobot/platforms/pebble/pebble_driver_test.go

73 lines
1.6 KiB
Go
Raw Normal View History

2014-05-02 17:22:05 -05:00
package pebble
import (
2014-06-13 14:18:57 -07:00
"testing"
2014-11-04 20:55:24 -08:00
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
2014-05-02 17:22:05 -05:00
)
var _ gobot.Driver = (*PebbleDriver)(nil)
2014-06-13 16:01:39 -07:00
func initTestPebbleDriver() *PebbleDriver {
return NewPebbleDriver(NewPebbleAdaptor("adaptor"), "pebble")
2014-06-13 14:18:57 -07:00
}
2014-06-13 16:01:39 -07:00
func TestPebbleDriverStart(t *testing.T) {
d := initTestPebbleDriver()
gobottest.Assert(t, len(d.Start()), 0)
2014-06-13 14:18:57 -07:00
}
2014-06-13 16:01:39 -07:00
func TestPebbleDriverHalt(t *testing.T) {
d := initTestPebbleDriver()
gobottest.Assert(t, len(d.Halt()), 0)
2014-06-13 14:18:57 -07:00
}
2014-11-04 20:55:24 -08:00
func TestPebbleDriver(t *testing.T) {
2014-06-13 16:01:39 -07:00
d := initTestPebbleDriver()
2014-12-17 14:04:18 -08:00
gobottest.Assert(t, d.Name(), "pebble")
gobottest.Assert(t, d.Connection().Name(), "adaptor")
2014-12-17 14:04:18 -08:00
2014-11-04 20:55:24 -08:00
sem := make(chan bool)
2014-06-13 16:01:39 -07:00
d.SendNotification("Hello")
d.SendNotification("World")
gobottest.Assert(t, d.Messages[0], "Hello")
gobottest.Assert(t, d.PendingMessage(), "Hello")
gobottest.Assert(t, d.PendingMessage(), "World")
gobottest.Assert(t, d.PendingMessage(), "")
2014-11-04 20:55:24 -08:00
gobot.On(d.Event("button"), func(data interface{}) {
sem <- true
})
d.PublishEvent("button", "")
select {
case <-sem:
case <-time.After(100 * time.Millisecond):
t.Errorf("Button Event was not published")
}
gobot.On(d.Event("accel"), func(data interface{}) {
sem <- true
})
d.Command("publish_event")(map[string]interface{}{"name": "accel", "data": "100"})
select {
case <-sem:
case <-time.After(100 * time.Millisecond):
t.Errorf("Accel Event was not published")
}
d.Command("send_notification")(map[string]interface{}{"message": "Hey buddy!"})
gobottest.Assert(t, d.Messages[0], "Hey buddy!")
2014-11-04 20:55:24 -08:00
message := d.Command("pending_message")(map[string]interface{}{})
gobottest.Assert(t, message, "Hey buddy!")
2014-11-04 20:55:24 -08:00
2014-06-13 14:18:57 -07:00
}