Skip to content

Commit

Permalink
core: update Sphero platform to simply return error
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Nov 7, 2016
1 parent 16e4184 commit e3f32bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions platforms/sphero/sphero_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func (a *Adaptor) Port() string { return a.port }
func (a *Adaptor) SetPort(p string) { a.port = p }

// Connect initiates a connection to the Sphero. Returns true on successful connection.
func (a *Adaptor) Connect() (errs []error) {
if sp, err := a.connect(a.Port()); err != nil {
return []error{err}
func (a *Adaptor) Connect() (err error) {
if sp, e := a.connect(a.Port()); e != nil {
return e
} else {
a.sp = sp
a.connected = true
Expand All @@ -45,25 +45,25 @@ func (a *Adaptor) Connect() (errs []error) {
// Reconnect attempts to reconnect to the Sphero. If the Sphero has an active connection
// it will first close that connection and then establish a new connection.
// Returns true on Successful reconnection
func (a *Adaptor) Reconnect() (errs []error) {
func (a *Adaptor) Reconnect() (err error) {
if a.connected {
a.Disconnect()
}
return a.Connect()
}

// Disconnect terminates the connection to the Sphero. Returns true on successful disconnect.
func (a *Adaptor) Disconnect() (errs []error) {
func (a *Adaptor) Disconnect() error {
if a.connected {
if err := a.sp.Close(); err != nil {
return []error{err}
if e := a.sp.Close(); e != nil {
return e
}
a.connected = false
}
return
return nil
}

// Finalize finalizes the Sphero Adaptor
func (a *Adaptor) Finalize() (errs []error) {
func (a *Adaptor) Finalize() error {
return a.Disconnect()
}
8 changes: 4 additions & 4 deletions platforms/sphero/sphero_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ func TestSpheroAdaptorReconnect(t *testing.T) {
func TestSpheroAdaptorFinalize(t *testing.T) {
a := initTestSpheroAdaptor()
a.Connect()
gobottest.Assert(t, len(a.Finalize()), 0)
gobottest.Assert(t, a.Finalize(), nil)

testAdaptorClose = func() error {
return errors.New("close error")
}

a.connected = true
gobottest.Assert(t, a.Finalize()[0], errors.New("close error"))
gobottest.Assert(t, a.Finalize(), errors.New("close error"))
}

func TestSpheroAdaptorConnect(t *testing.T) {
a := initTestSpheroAdaptor()
gobottest.Assert(t, len(a.Connect()), 0)
gobottest.Assert(t, a.Connect(), nil)

a.connect = func(string) (io.ReadWriteCloser, error) {
return nil, errors.New("connect error")
}

gobottest.Assert(t, a.Connect()[0], errors.New("connect error"))
gobottest.Assert(t, a.Connect(), errors.New("connect error"))
}
4 changes: 2 additions & 2 deletions platforms/sphero/sphero_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ func TestSpheroDriver(t *testing.T) {

func TestSpheroDriverStart(t *testing.T) {
d := initTestSpheroDriver()
gobottest.Assert(t, len(d.Start()), 0)
gobottest.Assert(t, d.Start(), nil)
}

func TestSpheroDriverHalt(t *testing.T) {
d := initTestSpheroDriver()
d.adaptor().connected = true
gobottest.Assert(t, len(d.Halt()), 0)
gobottest.Assert(t, d.Halt(), nil)
}

func TestSpheroDriverSetDataStreaming(t *testing.T) {
Expand Down

0 comments on commit e3f32bb

Please sign in to comment.