1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
hybridgroup.gobot/platforms/joystick/joystick_adaptor_test.go
Thomas Kohler 865e724af0
Build(v2): revert move to v2 subfolder (#932)
* revert move to v2 subfolder
* fix CI and adjust CHANGELOG
2023-05-29 19:23:28 +02:00

43 lines
835 B
Go

package joystick
import (
"errors"
"strings"
"testing"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Adaptor = (*Adaptor)(nil)
func initTestAdaptor() *Adaptor {
a := NewAdaptor()
a.connect = func(j *Adaptor) (err error) {
j.joystick = &testJoystick{}
return nil
}
return a
}
func TestJoystickAdaptorName(t *testing.T) {
a := initTestAdaptor()
gobottest.Assert(t, strings.HasPrefix(a.Name(), "Joystick"), true)
a.SetName("NewName")
gobottest.Assert(t, a.Name(), "NewName")
}
func TestAdaptorConnect(t *testing.T) {
a := initTestAdaptor()
gobottest.Assert(t, a.Connect(), nil)
a = NewAdaptor()
gobottest.Assert(t, a.Connect(), errors.New("No joystick available"))
}
func TestAdaptorFinalize(t *testing.T) {
a := initTestAdaptor()
a.Connect()
gobottest.Assert(t, a.Finalize(), nil)
}