gobot.io/x/gobot/v2@v2.1.0/platforms/leap/leap_motion_adaptor_test.go (about) 1 package leap 2 3 import ( 4 "errors" 5 "io" 6 "strings" 7 "testing" 8 9 "gobot.io/x/gobot/v2" 10 "gobot.io/x/gobot/v2/gobottest" 11 ) 12 13 var _ gobot.Adaptor = (*Adaptor)(nil) 14 15 func initTestLeapMotionAdaptor() *Adaptor { 16 a := NewAdaptor("") 17 a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, nil } 18 return a 19 } 20 21 func TestLeapMotionAdaptor(t *testing.T) { 22 a := NewAdaptor("127.0.0.1") 23 gobottest.Assert(t, a.Port(), "127.0.0.1") 24 } 25 26 func TestLeapMotionAdaptorName(t *testing.T) { 27 a := NewAdaptor("127.0.0.1") 28 gobottest.Assert(t, strings.HasPrefix(a.Name(), "Leap"), true) 29 a.SetName("NewName") 30 gobottest.Assert(t, a.Name(), "NewName") 31 } 32 33 func TestLeapMotionAdaptorConnect(t *testing.T) { 34 a := initTestLeapMotionAdaptor() 35 gobottest.Assert(t, a.Connect(), nil) 36 37 a.connect = func(port string) (io.ReadWriteCloser, error) { 38 return nil, errors.New("connection error") 39 } 40 gobottest.Assert(t, a.Connect(), errors.New("connection error")) 41 } 42 43 func TestLeapMotionAdaptorFinalize(t *testing.T) { 44 a := initTestLeapMotionAdaptor() 45 gobottest.Assert(t, a.Finalize(), nil) 46 }