1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-08 19:29:16 +08:00
hybridgroup.gobot/platforms/ble/generic_access_driver_test.go
2023-11-15 20:51:52 +01:00

52 lines
1.2 KiB
Go

package ble
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gobot.io/x/gobot/v2"
)
var _ gobot.Driver = (*GenericAccessDriver)(nil)
func initTestGenericAccessDriver() *GenericAccessDriver {
d := NewGenericAccessDriver(NewBleTestAdaptor())
return d
}
func TestGenericAccessDriver(t *testing.T) {
d := initTestGenericAccessDriver()
assert.True(t, strings.HasPrefix(d.Name(), "GenericAccess"))
d.SetName("NewName")
assert.Equal(t, "NewName", d.Name())
}
func TestGenericAccessDriverStartAndHalt(t *testing.T) {
d := initTestGenericAccessDriver()
require.NoError(t, d.Start())
require.NoError(t, d.Halt())
}
func TestGenericAccessDriverGetDeviceName(t *testing.T) {
a := NewBleTestAdaptor()
d := NewGenericAccessDriver(a)
a.TestReadCharacteristic(func(cUUID string) ([]byte, error) {
return []byte("TestDevice"), nil
})
assert.Equal(t, "TestDevice", d.GetDeviceName())
}
func TestGenericAccessDriverGetAppearance(t *testing.T) {
a := NewBleTestAdaptor()
d := NewGenericAccessDriver(a)
a.TestReadCharacteristic(func(cUUID string) ([]byte, error) {
return []byte{128, 0}, nil
})
assert.Equal(t, "Generic Computer", d.GetAppearance())
}