Skip to content

Commit

Permalink
tests: refactor test interfaces out of implementations and into the t…
Browse files Browse the repository at this point in the history
…ests where they belong

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Aug 26, 2016
1 parent 986cfaa commit a64f56d
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 49 deletions.
4 changes: 0 additions & 4 deletions platforms/audio/audio_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import (
"os"
"os/exec"
"path"

"github.com/hybridgroup/gobot"
)

var _ gobot.Adaptor = (*AudioAdaptor)(nil)

type AudioAdaptor struct {
name string
}
Expand Down
3 changes: 3 additions & 0 deletions platforms/audio/audio_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"os/exec"
"testing"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
)

var _ gobot.Adaptor = (*AudioAdaptor)(nil)

func TestAudioAdaptor(t *testing.T) {
a := NewAudioAdaptor("tester")

Expand Down
2 changes: 0 additions & 2 deletions platforms/audio/audio_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"time"
)

var _ gobot.Driver = (*AudioDriver)(nil)

type AudioDriver struct {
name string
connection gobot.Connection
Expand Down
3 changes: 3 additions & 0 deletions platforms/audio/audio_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"os/exec"
"testing"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
)

var _ gobot.Driver = (*AudioDriver)(nil)

func TestAudioDriver(t *testing.T) {
d := NewAudioDriver(NewAudioAdaptor("conn"), "dev", "../../examples/laser.mp3")

Expand Down
12 changes: 0 additions & 12 deletions platforms/beaglebone/beaglebone_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@ import (
"strings"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/i2c"
"github.com/hybridgroup/gobot/sysfs"
)

var _ gobot.Adaptor = (*BeagleboneAdaptor)(nil)

var _ gpio.DigitalReader = (*BeagleboneAdaptor)(nil)
var _ gpio.DigitalWriter = (*BeagleboneAdaptor)(nil)
var _ gpio.AnalogReader = (*BeagleboneAdaptor)(nil)
var _ gpio.PwmWriter = (*BeagleboneAdaptor)(nil)
var _ gpio.ServoWriter = (*BeagleboneAdaptor)(nil)

var _ i2c.I2c = (*BeagleboneAdaptor)(nil)

var slots = "/sys/devices/bone_capemgr.*"
var ocp = "/sys/devices/ocp.*"
var usrLed = "/sys/devices/ocp.3/gpio-leds.8/leds/beaglebone:green:"
Expand Down
13 changes: 13 additions & 0 deletions platforms/beaglebone/beaglebone_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ import (
"strings"
"testing"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/i2c"
"github.com/hybridgroup/gobot/sysfs"
)

var _ gobot.Adaptor = (*BeagleboneAdaptor)(nil)

var _ gpio.DigitalReader = (*BeagleboneAdaptor)(nil)
var _ gpio.DigitalWriter = (*BeagleboneAdaptor)(nil)
var _ gpio.AnalogReader = (*BeagleboneAdaptor)(nil)
var _ gpio.PwmWriter = (*BeagleboneAdaptor)(nil)
var _ gpio.ServoWriter = (*BeagleboneAdaptor)(nil)

var _ i2c.I2c = (*BeagleboneAdaptor)(nil)

type NullReadWriteCloser struct {
contents []byte
}
Expand Down
3 changes: 0 additions & 3 deletions platforms/ble/ble_client_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (

func initTestBLEClientAdaptor() *BLEClientAdaptor {
a := NewBLEClientAdaptor("bot", "D7:99:5A:26:EC:38")
// a.connect = func(n *BLEAdaptor) (io.ReadWriteCloser, error) {
// return &NullReadWriteCloser{}, nil
// }
return a
}

Expand Down
10 changes: 0 additions & 10 deletions platforms/chip/chip_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@ package chip
import (
"errors"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/i2c"
"github.com/hybridgroup/gobot/sysfs"
)

var _ gobot.Adaptor = (*ChipAdaptor)(nil)

var _ gpio.DigitalReader = (*ChipAdaptor)(nil)
var _ gpio.DigitalWriter = (*ChipAdaptor)(nil)

var _ i2c.I2c = (*ChipAdaptor)(nil)

type ChipAdaptor struct {
name string
digitalPins map[int]sysfs.DigitalPin
Expand Down
10 changes: 10 additions & 0 deletions platforms/chip/chip_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ import (
"errors"
"testing"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/i2c"
"github.com/hybridgroup/gobot/sysfs"
)

var _ gobot.Adaptor = (*ChipAdaptor)(nil)

var _ gpio.DigitalReader = (*ChipAdaptor)(nil)
var _ gpio.DigitalWriter = (*ChipAdaptor)(nil)

var _ i2c.I2c = (*ChipAdaptor)(nil)

type NullReadWriteCloser struct {
contents []byte
}
Expand Down
12 changes: 0 additions & 12 deletions platforms/firmata/firmata_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@ import (

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata/client"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/i2c"
"github.com/tarm/goserial"
)

var _ gobot.Adaptor = (*FirmataAdaptor)(nil)

var _ gpio.DigitalReader = (*FirmataAdaptor)(nil)
var _ gpio.DigitalWriter = (*FirmataAdaptor)(nil)
var _ gpio.AnalogReader = (*FirmataAdaptor)(nil)
var _ gpio.PwmWriter = (*FirmataAdaptor)(nil)
var _ gpio.ServoWriter = (*FirmataAdaptor)(nil)

var _ i2c.I2c = (*FirmataAdaptor)(nil)

type firmataBoard interface {
Connect(io.ReadWriteCloser) error
Disconnect() error
Expand Down
12 changes: 12 additions & 0 deletions platforms/firmata/firmata_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
"github.com/hybridgroup/gobot/platforms/firmata/client"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/i2c"
)

var _ gobot.Adaptor = (*FirmataAdaptor)(nil)

var _ gpio.DigitalReader = (*FirmataAdaptor)(nil)
var _ gpio.DigitalWriter = (*FirmataAdaptor)(nil)
var _ gpio.AnalogReader = (*FirmataAdaptor)(nil)
var _ gpio.PwmWriter = (*FirmataAdaptor)(nil)
var _ gpio.ServoWriter = (*FirmataAdaptor)(nil)

var _ i2c.I2c = (*FirmataAdaptor)(nil)

type readWriteCloser struct{}

func (readWriteCloser) Write(p []byte) (int, error) {
Expand Down
3 changes: 0 additions & 3 deletions platforms/joystick/joystick_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import (
"errors"

"github.com/veandco/go-sdl2/sdl"
"github.com/hybridgroup/gobot"
)

var _ gobot.Adaptor = (*JoystickAdaptor)(nil)

type joystick interface {
Close()
InstanceID() sdl.JoystickID
Expand Down
3 changes: 3 additions & 0 deletions platforms/joystick/joystick_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import (
"errors"
"testing"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
)

var _ gobot.Adaptor = (*JoystickAdaptor)(nil)

func initTestJoystickAdaptor() *JoystickAdaptor {
a := NewJoystickAdaptor("bot")
a.connect = func(j *JoystickAdaptor) (err error) {
Expand Down
4 changes: 1 addition & 3 deletions platforms/joystick/joystick_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"io/ioutil"
"time"

"github.com/veandco/go-sdl2/sdl"
"github.com/hybridgroup/gobot"
"github.com/veandco/go-sdl2/sdl"
)

var _ gobot.Driver = (*JoystickDriver)(nil)

// JoystickDriver represents a joystick
type JoystickDriver struct {
name string
Expand Down
2 changes: 2 additions & 0 deletions platforms/joystick/joystick_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/veandco/go-sdl2/sdl"
)

var _ gobot.Driver = (*JoystickDriver)(nil)

func initTestJoystickDriver() *JoystickDriver {
a := NewJoystickAdaptor("bot")
a.connect = func(j *JoystickAdaptor) (err error) {
Expand Down

0 comments on commit a64f56d

Please sign in to comment.