hybridgroup.gobot/platforms/joystick/joystick_adaptor_test.go

45 lines
852 B
Go
Raw Normal View History

2014-04-28 09:02:39 +08:00
package joystick
import (
"strings"
2014-06-14 03:54:21 +08:00
"testing"
2014-07-23 04:55:19 +08:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gobot.io/x/gobot/v2"
)
var _ gobot.Adaptor = (*Adaptor)(nil)
func initTestAdaptor() *Adaptor {
a := NewAdaptor("6")
a.connect = func(j *Adaptor) error {
2014-07-23 04:55:19 +08:00
j.joystick = &testJoystick{}
2014-11-20 07:45:59 +08:00
return nil
2014-07-23 04:55:19 +08:00
}
return a
2014-06-14 03:54:21 +08:00
}
func TestJoystickAdaptorName(t *testing.T) {
a := initTestAdaptor()
assert.True(t, strings.HasPrefix(a.Name(), "Joystick"))
a.SetName("NewName")
assert.Equal(t, "NewName", a.Name())
}
func TestAdaptorConnect(t *testing.T) {
a := initTestAdaptor()
require.NoError(t, a.Connect())
2014-11-20 10:54:31 +08:00
a = NewAdaptor("6")
err := a.Connect()
require.ErrorContains(t, err, "no joystick available")
2014-06-14 03:54:21 +08:00
}
2014-06-14 07:01:39 +08:00
func TestAdaptorFinalize(t *testing.T) {
a := initTestAdaptor()
_ = a.Connect()
require.NoError(t, a.Finalize())
2014-06-14 03:54:21 +08:00
}