hybridgroup.gobot/platforms/keyboard/keyboard_driver_test.go

46 lines
924 B
Go
Raw Normal View History

2015-07-10 02:33:46 +08:00
package keyboard
import (
"os"
"strings"
2015-07-10 02:33:46 +08:00
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gobot.io/x/gobot/v2"
2015-07-10 02:33:46 +08:00
)
var _ gobot.Driver = (*Driver)(nil)
func initTestKeyboardDriver() *Driver {
d := NewDriver()
d.connect = func(k *Driver) (err error) {
2015-07-10 02:33:46 +08:00
k.stdin = &os.File{}
return nil
}
d.listen = func(k *Driver) {}
2015-07-10 02:33:46 +08:00
return d
}
func TestKeyboardDriver(t *testing.T) {
d := initTestKeyboardDriver()
assert.Equal(t, (gobot.Connection)(nil), d.Connection())
2015-07-10 02:33:46 +08:00
}
func TestKeyboardDriverName(t *testing.T) {
d := initTestKeyboardDriver()
assert.True(t, strings.HasPrefix(d.Name(), "Keyboard"))
d.SetName("NewName")
assert.Equal(t, "NewName", d.Name())
}
2015-07-10 02:33:46 +08:00
func TestKeyboardDriverStart(t *testing.T) {
d := initTestKeyboardDriver()
require.NoError(t, d.Start())
2015-07-10 02:33:46 +08:00
}
func TestKeyboardDriverHalt(t *testing.T) {
d := initTestKeyboardDriver()
require.NoError(t, d.Halt())
2015-07-10 02:33:46 +08:00
}