Skip to content

Commit

Permalink
Rename test helpers so they don't impact coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Dec 18, 2014
1 parent 7200bf1 commit 52e3ffc
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func initTestAPI() *api {
log.SetOutput(gobot.NullReadWriteCloser{})
log.SetOutput(NullReadWriteCloser{})
g := gobot.NewGobot()
a := NewAPI(g)
a.start = func(m *api) {}
Expand Down
14 changes: 14 additions & 0 deletions api/test_helper.go → api/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import (
"github.com/hybridgroup/gobot"
)

type NullReadWriteCloser struct{}

func (NullReadWriteCloser) Write(p []byte) (int, error) {
return len(p), nil
}

func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil
}

func (NullReadWriteCloser) Close() error {
return nil
}

type testDriver struct {
name string
pin string
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions platforms/firmata/firmata_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func initTestFirmataAdaptor() *FirmataAdaptor {
a := NewFirmataAdaptor("board", "/dev/null")
a.connect = func(f *FirmataAdaptor) (err error) {
f.board = newBoard(gobot.NullReadWriteCloser{})
f.board = newBoard(NullReadWriteCloser{})
f.board.initTimeInterval = 0 * time.Second
// arduino uno r3 firmware response "StandardFirmata.ino"
f.board.process([]byte{240, 121, 2, 3, 83, 0, 116, 0, 97, 0, 110, 0, 100,
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestFirmataAdaptorConnect(t *testing.T) {
a := initTestFirmataAdaptor()
gobot.Assert(t, len(a.Connect()), 0)

a = NewFirmataAdaptor("board", gobot.NullReadWriteCloser{})
a = NewFirmataAdaptor("board", NullReadWriteCloser{})
gobot.Assert(t, a.connect(a), nil)
}

Expand Down
16 changes: 15 additions & 1 deletion platforms/firmata/firmata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@ import (
"github.com/hybridgroup/gobot"
)

type NullReadWriteCloser struct{}

func (NullReadWriteCloser) Write(p []byte) (int, error) {
return len(p), nil
}

func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil
}

func (NullReadWriteCloser) Close() error {
return nil
}

func initTestFirmata() *board {
b := newBoard(gobot.NullReadWriteCloser{})
b := newBoard(NullReadWriteCloser{})
b.initTimeInterval = 0 * time.Second
// arduino uno r3 firmware response "StandardFirmata.ino"
b.process([]byte{240, 121, 2, 3, 83, 0, 116, 0, 97, 0, 110, 0, 100, 0, 97,
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 15 additions & 1 deletion platforms/intel-iot/edison/edison_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ import (
"github.com/hybridgroup/gobot/sysfs"
)

type NullReadWriteCloser struct{}

func (NullReadWriteCloser) Write(p []byte) (int, error) {
return len(p), nil
}

func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil
}

func (NullReadWriteCloser) Close() error {
return nil
}

func initTestEdisonAdaptor() (*EdisonAdaptor, *sysfs.MockFilesystem) {
a := NewEdisonAdaptor("myAdaptor")
fs := sysfs.NewMockFilesystem([]string{
Expand Down Expand Up @@ -93,7 +107,7 @@ func TestEdisonAdaptorFinalize(t *testing.T) {
a, _ := initTestEdisonAdaptor()
a.DigitalWrite("3", 1)
a.PwmWrite("5", 100)
a.i2cDevice = new(gobot.NullReadWriteCloser)
a.i2cDevice = new(NullReadWriteCloser)
gobot.Assert(t, len(a.Finalize()), 0)
}

Expand Down
14 changes: 13 additions & 1 deletion platforms/leap/leap_motion_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ import (
"github.com/hybridgroup/gobot"
)

type NullReadWriteCloser struct{}

func (NullReadWriteCloser) Write(p []byte) (int, error) {
return len(p), nil
}
func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil
}
func (NullReadWriteCloser) Close() error {
return nil
}

func initTestLeapMotionDriver() *LeapMotionDriver {
a := NewLeapMotionAdaptor("bot", "")
a.connect = func(l *LeapMotionAdaptor) (err error) {
l.ws = new(gobot.NullReadWriteCloser)
l.ws = new(NullReadWriteCloser)
return nil
}
a.Connect()
Expand Down
14 changes: 13 additions & 1 deletion platforms/neurosky/neurosky_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ import (
"github.com/hybridgroup/gobot"
)

type NullReadWriteCloser struct{}

func (NullReadWriteCloser) Write(p []byte) (int, error) {
return len(p), nil
}
func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil
}
func (NullReadWriteCloser) Close() error {
return nil
}

func initTestNeuroskyAdaptor() *NeuroskyAdaptor {
a := NewNeuroskyAdaptor("bot", "/dev/null")
a.connect = func(n *NeuroskyAdaptor) (err error) {
n.sp = gobot.NullReadWriteCloser{}
n.sp = NullReadWriteCloser{}
return nil
}
return a
Expand Down
2 changes: 1 addition & 1 deletion platforms/neurosky/neurosky_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func initTestNeuroskyDriver() *NeuroskyDriver {
a := NewNeuroskyAdaptor("bot", "/dev/null")
a.connect = func(n *NeuroskyAdaptor) (err error) {
n.sp = gobot.NullReadWriteCloser{}
n.sp = NullReadWriteCloser{}
return nil
}
a.connect(a)
Expand Down
14 changes: 13 additions & 1 deletion platforms/raspi/raspi_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import (
"github.com/hybridgroup/gobot/sysfs"
)

type NullReadWriteCloser struct{}

func (NullReadWriteCloser) Write(p []byte) (int, error) {
return len(p), nil
}
func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil
}
func (NullReadWriteCloser) Close() error {
return nil
}

func initTestRaspiAdaptor() *RaspiAdaptor {
readFile = func() ([]byte, error) {
return []byte(`
Expand Down Expand Up @@ -65,7 +77,7 @@ func TestRaspiAdaptorFinalize(t *testing.T) {

sysfs.SetFilesystem(fs)
a.DigitalWrite("3", 1)
a.i2cDevice = new(gobot.NullReadWriteCloser)
a.i2cDevice = new(NullReadWriteCloser)
gobot.Assert(t, len(a.Finalize()), 0)
}

Expand Down

0 comments on commit 52e3ffc

Please sign in to comment.