gobot.io/x/gobot@v1.16.0/platforms/keyboard/keyboard_driver_test.go (about) 1 package keyboard 2 3 import ( 4 "os" 5 "strings" 6 "testing" 7 8 "gobot.io/x/gobot" 9 "gobot.io/x/gobot/gobottest" 10 ) 11 12 var _ gobot.Driver = (*Driver)(nil) 13 14 func initTestKeyboardDriver() *Driver { 15 d := NewDriver() 16 d.connect = func(k *Driver) (err error) { 17 k.stdin = &os.File{} 18 return nil 19 } 20 d.listen = func(k *Driver) {} 21 return d 22 } 23 24 func TestKeyboardDriver(t *testing.T) { 25 d := initTestKeyboardDriver() 26 gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil)) 27 } 28 29 func TestKeyboardDriverName(t *testing.T) { 30 d := initTestKeyboardDriver() 31 gobottest.Assert(t, strings.HasPrefix(d.Name(), "Keyboard"), true) 32 d.SetName("NewName") 33 gobottest.Assert(t, d.Name(), "NewName") 34 } 35 36 func TestKeyboardDriverStart(t *testing.T) { 37 d := initTestKeyboardDriver() 38 gobottest.Assert(t, d.Start(), nil) 39 } 40 41 func TestKeyboardDriverHalt(t *testing.T) { 42 d := initTestKeyboardDriver() 43 gobottest.Assert(t, d.Halt(), nil) 44 }