1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-09 19:29:27 +08:00
hybridgroup.gobot/platforms/ble/battery_driver_test.go
deadprogram 72039de2b6 ble: refactoring drivers to use BLEConnector interface and provide tests
Signed-off-by: deadprogram <ron@hybridgroup.com>
2017-04-05 11:47:28 +02:00

32 lines
627 B
Go

package ble
import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
)
var _ gobot.Driver = (*BatteryDriver)(nil)
func initTestBatteryDriver() *BatteryDriver {
d := NewBatteryDriver(newBleTestAdaptor())
return d
}
func TestBatteryDriver(t *testing.T) {
d := initTestBatteryDriver()
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Battery"), true)
}
func TestBatteryDriverRead(t *testing.T) {
a := newBleTestAdaptor()
d := NewBatteryDriver(a)
a.TestReadCharacteristic(func(cUUID string) ([]byte, error) {
return []byte{20}, nil
})
gobottest.Assert(t, d.GetBatteryLevel(), uint8(20))
}