gobot.io/x/gobot@v1.16.0/platforms/parrot/bebop/bebop_adaptor_test.go (about)

     1  package bebop
     2  
     3  import (
     4  	"errors"
     5  	"strings"
     6  	"testing"
     7  
     8  	"gobot.io/x/gobot"
     9  	"gobot.io/x/gobot/gobottest"
    10  )
    11  
    12  var _ gobot.Adaptor = (*Adaptor)(nil)
    13  
    14  func initTestBebopAdaptor() *Adaptor {
    15  	a := NewAdaptor()
    16  	a.connect = func(b *Adaptor) (err error) {
    17  		b.drone = &testDrone{}
    18  		return nil
    19  	}
    20  	return a
    21  }
    22  
    23  func TestBebopAdaptorName(t *testing.T) {
    24  	a := NewAdaptor()
    25  	gobottest.Assert(t, strings.HasPrefix(a.Name(), "Bebop"), true)
    26  	a.SetName("NewName")
    27  	gobottest.Assert(t, a.Name(), "NewName")
    28  }
    29  
    30  func TestBebopAdaptorConnect(t *testing.T) {
    31  	a := initTestBebopAdaptor()
    32  	gobottest.Assert(t, a.Connect(), nil)
    33  
    34  	a.connect = func(a *Adaptor) error {
    35  		return errors.New("connection error")
    36  	}
    37  	gobottest.Assert(t, a.Connect(), errors.New("connection error"))
    38  }
    39  
    40  func TestBebopAdaptorFinalize(t *testing.T) {
    41  	a := initTestBebopAdaptor()
    42  	a.Connect()
    43  	gobottest.Assert(t, a.Finalize(), nil)
    44  }