gobot.io/x/gobot/v2@v2.1.0/platforms/parrot/ardrone/ardrone_adaptor_test.go (about) 1 package ardrone 2 3 import ( 4 "errors" 5 "strings" 6 "testing" 7 8 "gobot.io/x/gobot/v2" 9 "gobot.io/x/gobot/v2/gobottest" 10 ) 11 12 var _ gobot.Adaptor = (*Adaptor)(nil) 13 14 func initTestArdroneAdaptor() *Adaptor { 15 a := NewAdaptor() 16 a.connect = func(a *Adaptor) (drone, error) { 17 return &testDrone{}, nil 18 } 19 return a 20 } 21 22 func TestArdroneAdaptor(t *testing.T) { 23 a := NewAdaptor() 24 gobottest.Assert(t, a.config.Ip, "192.168.1.1") 25 26 a = NewAdaptor("192.168.100.100") 27 gobottest.Assert(t, a.config.Ip, "192.168.100.100") 28 } 29 30 func TestArdroneAdaptorConnect(t *testing.T) { 31 a := initTestArdroneAdaptor() 32 gobottest.Assert(t, a.Connect(), nil) 33 34 a.connect = func(a *Adaptor) (drone, error) { 35 return nil, errors.New("connection error") 36 } 37 gobottest.Assert(t, a.Connect(), errors.New("connection error")) 38 } 39 40 func TestArdroneAdaptorName(t *testing.T) { 41 a := initTestArdroneAdaptor() 42 gobottest.Assert(t, strings.HasPrefix(a.Name(), "ARDrone"), true) 43 a.SetName("NewName") 44 gobottest.Assert(t, a.Name(), "NewName") 45 } 46 47 func TestArdroneAdaptorFinalize(t *testing.T) { 48 a := initTestArdroneAdaptor() 49 gobottest.Assert(t, a.Finalize(), nil) 50 }