gobot.io/x/gobot/v2@v2.1.0/platforms/joystick/joystick_adaptor_test.go (about)

     1  package joystick
     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 initTestAdaptor() *Adaptor {
    15  	a := NewAdaptor()
    16  	a.connect = func(j *Adaptor) (err error) {
    17  		j.joystick = &testJoystick{}
    18  		return nil
    19  	}
    20  	return a
    21  }
    22  
    23  func TestJoystickAdaptorName(t *testing.T) {
    24  	a := initTestAdaptor()
    25  	gobottest.Assert(t, strings.HasPrefix(a.Name(), "Joystick"), true)
    26  	a.SetName("NewName")
    27  	gobottest.Assert(t, a.Name(), "NewName")
    28  }
    29  
    30  func TestAdaptorConnect(t *testing.T) {
    31  	a := initTestAdaptor()
    32  	gobottest.Assert(t, a.Connect(), nil)
    33  
    34  	a = NewAdaptor()
    35  	gobottest.Assert(t, a.Connect(), errors.New("No joystick available"))
    36  }
    37  
    38  func TestAdaptorFinalize(t *testing.T) {
    39  	a := initTestAdaptor()
    40  	a.Connect()
    41  	gobottest.Assert(t, a.Finalize(), nil)
    42  }