From 66af2582e9c23c1637098572be98808a248b16e2 Mon Sep 17 00:00:00 2001 From: Stuart Leeks Date: Mon, 30 Mar 2020 21:36:32 +0100 Subject: [PATCH] Update function signatures in gpioTestAdaptor --- drivers/gpio/button_driver_test.go | 12 +++--- drivers/gpio/buzzer_driver_test.go | 6 +-- drivers/gpio/direct_pin_driver_test.go | 8 ++-- drivers/gpio/grove_drivers_test.go | 4 +- drivers/gpio/helpers_test.go | 50 ++++++++++++------------ drivers/gpio/led_driver_test.go | 10 ++--- drivers/gpio/makey_button_driver_test.go | 8 ++-- drivers/gpio/pir_motion_driver_test.go | 6 +-- drivers/gpio/relay_driver_test.go | 4 +- drivers/gpio/rgb_led_driver_test.go | 10 ++--- drivers/gpio/servo_driver_test.go | 2 +- 11 files changed, 60 insertions(+), 60 deletions(-) diff --git a/drivers/gpio/button_driver_test.go b/drivers/gpio/button_driver_test.go index 214046281..2a56ac93b 100644 --- a/drivers/gpio/button_driver_test.go +++ b/drivers/gpio/button_driver_test.go @@ -44,7 +44,7 @@ func TestButtonDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 1 return }) @@ -62,7 +62,7 @@ func TestButtonDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 0 return }) @@ -77,7 +77,7 @@ func TestButtonDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { err = errors.New("digital read error") return }) @@ -94,7 +94,7 @@ func TestButtonDriverStart(t *testing.T) { d.halt <- true - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 1 return }) @@ -117,7 +117,7 @@ func TestButtonDriverDefaultState(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 0 return }) @@ -135,7 +135,7 @@ func TestButtonDriverDefaultState(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 1 return }) diff --git a/drivers/gpio/buzzer_driver_test.go b/drivers/gpio/buzzer_driver_test.go index 796e862d6..f72798b01 100644 --- a/drivers/gpio/buzzer_driver_test.go +++ b/drivers/gpio/buzzer_driver_test.go @@ -53,7 +53,7 @@ func TestBuzzerDriverTone(t *testing.T) { func TestBuzzerDriverOnError(t *testing.T) { a := newGpioTestAdaptor() d := initTestBuzzerDriver(a) - a.TestAdaptorDigitalWrite(func() (err error) { + a.TestAdaptorDigitalWrite(func(string, byte) (err error) { return errors.New("write error") }) @@ -63,7 +63,7 @@ func TestBuzzerDriverOnError(t *testing.T) { func TestBuzzerDriverOffError(t *testing.T) { a := newGpioTestAdaptor() d := initTestBuzzerDriver(a) - a.TestAdaptorDigitalWrite(func() (err error) { + a.TestAdaptorDigitalWrite(func(string, byte) (err error) { return errors.New("write error") }) @@ -73,7 +73,7 @@ func TestBuzzerDriverOffError(t *testing.T) { func TestBuzzerDriverToneError(t *testing.T) { a := newGpioTestAdaptor() d := initTestBuzzerDriver(a) - a.TestAdaptorDigitalWrite(func() (err error) { + a.TestAdaptorDigitalWrite(func(string, byte) (err error) { return errors.New("write error") }) diff --git a/drivers/gpio/direct_pin_driver_test.go b/drivers/gpio/direct_pin_driver_test.go index 3212d5110..6ecf78160 100644 --- a/drivers/gpio/direct_pin_driver_test.go +++ b/drivers/gpio/direct_pin_driver_test.go @@ -13,17 +13,17 @@ var _ gobot.Driver = (*DirectPinDriver)(nil) func initTestDirectPinDriver() *DirectPinDriver { a := newGpioTestAdaptor() - a.testAdaptorDigitalRead = func() (val int, err error) { + a.testAdaptorDigitalRead = func(string) (val int, err error) { val = 1 return } - a.testAdaptorDigitalWrite = func() (err error) { + a.testAdaptorDigitalWrite = func(string, byte) (err error) { return errors.New("write error") } - a.testAdaptorPwmWrite = func() (err error) { + a.testAdaptorPwmWrite = func(string, byte) (err error) { return errors.New("write error") } - a.testAdaptorServoWrite = func() (err error) { + a.testAdaptorServoWrite = func(string, byte) (err error) { return errors.New("write error") } return NewDirectPinDriver(a, "1") diff --git a/drivers/gpio/grove_drivers_test.go b/drivers/gpio/grove_drivers_test.go index ee769d787..d92ce3e07 100644 --- a/drivers/gpio/grove_drivers_test.go +++ b/drivers/gpio/grove_drivers_test.go @@ -53,7 +53,7 @@ func TestDigitalDriverHalt(t *testing.T) { for _, driver := range drivers { var callCount int32 - testAdaptor.testAdaptorDigitalRead = func() (int, error) { + testAdaptor.testAdaptorDigitalRead = func(string) (int, error) { atomic.AddInt32(&callCount, 1) return 42, nil } @@ -85,7 +85,7 @@ func TestDriverPublishesError(t *testing.T) { for _, driver := range drivers { sem := make(chan struct{}, 1) // send error - returnErr := func() (val int, err error) { + returnErr := func(string) (val int, err error) { err = errors.New("read error") return } diff --git a/drivers/gpio/helpers_test.go b/drivers/gpio/helpers_test.go index c7261bbdd..fe3849c09 100644 --- a/drivers/gpio/helpers_test.go +++ b/drivers/gpio/helpers_test.go @@ -19,63 +19,63 @@ type gpioTestAdaptor struct { name string port string mtx sync.Mutex - testAdaptorDigitalWrite func() (err error) - testAdaptorServoWrite func() (err error) - testAdaptorPwmWrite func() (err error) - testAdaptorAnalogRead func() (val int, err error) - testAdaptorDigitalRead func() (val int, err error) + testAdaptorDigitalWrite func(pin string, val byte) (err error) + testAdaptorServoWrite func(pin string, val byte) (err error) + testAdaptorPwmWrite func(pin string, val byte) (err error) + testAdaptorAnalogRead func(ping string) (val int, err error) + testAdaptorDigitalRead func(ping string) (val int, err error) } -func (t *gpioTestAdaptor) TestAdaptorDigitalWrite(f func() (err error)) { +func (t *gpioTestAdaptor) TestAdaptorDigitalWrite(f func(pin string, val byte) (err error)) { t.mtx.Lock() defer t.mtx.Unlock() t.testAdaptorDigitalWrite = f } -func (t *gpioTestAdaptor) TestAdaptorServoWrite(f func() (err error)) { +func (t *gpioTestAdaptor) TestAdaptorServoWrite(f func(pin string, val byte) (err error)) { t.mtx.Lock() defer t.mtx.Unlock() t.testAdaptorServoWrite = f } -func (t *gpioTestAdaptor) TestAdaptorPwmWrite(f func() (err error)) { +func (t *gpioTestAdaptor) TestAdaptorPwmWrite(f func(pin string, val byte) (err error)) { t.mtx.Lock() defer t.mtx.Unlock() t.testAdaptorPwmWrite = f } -func (t *gpioTestAdaptor) TestAdaptorAnalogRead(f func() (val int, err error)) { +func (t *gpioTestAdaptor) TestAdaptorAnalogRead(f func(pin string) (val int, err error)) { t.mtx.Lock() defer t.mtx.Unlock() t.testAdaptorAnalogRead = f } -func (t *gpioTestAdaptor) TestAdaptorDigitalRead(f func() (val int, err error)) { +func (t *gpioTestAdaptor) TestAdaptorDigitalRead(f func(pin string) (val int, err error)) { t.mtx.Lock() defer t.mtx.Unlock() t.testAdaptorDigitalRead = f } -func (t *gpioTestAdaptor) ServoWrite(string, byte) (err error) { +func (t *gpioTestAdaptor) ServoWrite(pin string, val byte) (err error) { t.mtx.Lock() defer t.mtx.Unlock() - return t.testAdaptorServoWrite() + return t.testAdaptorServoWrite(pin, val) } -func (t *gpioTestAdaptor) PwmWrite(string, byte) (err error) { +func (t *gpioTestAdaptor) PwmWrite(pin string, val byte) (err error) { t.mtx.Lock() defer t.mtx.Unlock() - return t.testAdaptorPwmWrite() + return t.testAdaptorPwmWrite(pin, val) } -func (t *gpioTestAdaptor) AnalogRead(string) (val int, err error) { +func (t *gpioTestAdaptor) AnalogRead(pin string) (val int, err error) { t.mtx.Lock() defer t.mtx.Unlock() - return t.testAdaptorAnalogRead() + return t.testAdaptorAnalogRead(pin) } -func (t *gpioTestAdaptor) DigitalRead(string) (val int, err error) { +func (t *gpioTestAdaptor) DigitalRead(pin string) (val int, err error) { t.mtx.Lock() defer t.mtx.Unlock() - return t.testAdaptorDigitalRead() + return t.testAdaptorDigitalRead(pin) } -func (t *gpioTestAdaptor) DigitalWrite(string, byte) (err error) { +func (t *gpioTestAdaptor) DigitalWrite(pin string, val byte) (err error) { t.mtx.Lock() defer t.mtx.Unlock() - return t.testAdaptorDigitalWrite() + return t.testAdaptorDigitalWrite(pin, val) } func (t *gpioTestAdaptor) Connect() (err error) { return } func (t *gpioTestAdaptor) Finalize() (err error) { return } @@ -86,19 +86,19 @@ func (t *gpioTestAdaptor) Port() string { return t.port } func newGpioTestAdaptor() *gpioTestAdaptor { return &gpioTestAdaptor{ port: "/dev/null", - testAdaptorDigitalWrite: func() (err error) { + testAdaptorDigitalWrite: func(pin string, val byte) (err error) { return nil }, - testAdaptorServoWrite: func() (err error) { + testAdaptorServoWrite: func(pin string, val byte) (err error) { return nil }, - testAdaptorPwmWrite: func() (err error) { + testAdaptorPwmWrite: func(pin string, val byte) (err error) { return nil }, - testAdaptorAnalogRead: func() (val int, err error) { + testAdaptorAnalogRead: func(pin string) (val int, err error) { return 99, nil }, - testAdaptorDigitalRead: func() (val int, err error) { + testAdaptorDigitalRead: func(pin string) (val int, err error) { return 1, nil }, } diff --git a/drivers/gpio/led_driver_test.go b/drivers/gpio/led_driver_test.go index cd3b9ff71..59e39e835 100644 --- a/drivers/gpio/led_driver_test.go +++ b/drivers/gpio/led_driver_test.go @@ -13,10 +13,10 @@ var _ gobot.Driver = (*LedDriver)(nil) func initTestLedDriver() *LedDriver { a := newGpioTestAdaptor() - a.testAdaptorDigitalWrite = func() (err error) { + a.testAdaptorDigitalWrite = func(string, byte) (err error) { return nil } - a.testAdaptorPwmWrite = func() (err error) { + a.testAdaptorPwmWrite = func(string, byte) (err error) { return nil } return NewLedDriver(a, "1") @@ -30,10 +30,10 @@ func TestLedDriver(t *testing.T) { gobottest.Assert(t, d.Pin(), "1") gobottest.Refute(t, d.Connection(), nil) - a.testAdaptorDigitalWrite = func() (err error) { + a.testAdaptorDigitalWrite = func(string, byte) (err error) { return errors.New("write error") } - a.testAdaptorPwmWrite = func() (err error) { + a.testAdaptorPwmWrite = func(string, byte) (err error) { return errors.New("pwm error") } @@ -73,7 +73,7 @@ func TestLedDriverToggle(t *testing.T) { func TestLedDriverBrightness(t *testing.T) { a := newGpioTestAdaptor() d := NewLedDriver(a, "1") - a.testAdaptorPwmWrite = func() (err error) { + a.testAdaptorPwmWrite = func(string, byte) (err error) { err = errors.New("pwm error") return } diff --git a/drivers/gpio/makey_button_driver_test.go b/drivers/gpio/makey_button_driver_test.go index bb9b2c083..54ffcafde 100644 --- a/drivers/gpio/makey_button_driver_test.go +++ b/drivers/gpio/makey_button_driver_test.go @@ -54,7 +54,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 0 return }) @@ -70,7 +70,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 1 return }) @@ -86,7 +86,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { err = errors.New("digital read error") return }) @@ -102,7 +102,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 1 return }) diff --git a/drivers/gpio/pir_motion_driver_test.go b/drivers/gpio/pir_motion_driver_test.go index 32de7ec1c..c11caf4b5 100644 --- a/drivers/gpio/pir_motion_driver_test.go +++ b/drivers/gpio/pir_motion_driver_test.go @@ -46,7 +46,7 @@ func TestPIRMotionDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 1 return }) @@ -62,7 +62,7 @@ func TestPIRMotionDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { val = 0 return }) @@ -77,7 +77,7 @@ func TestPIRMotionDriverStart(t *testing.T) { sem <- true }) - a.TestAdaptorDigitalRead(func() (val int, err error) { + a.TestAdaptorDigitalRead(func(string) (val int, err error) { err = errors.New("digital read error") return }) diff --git a/drivers/gpio/relay_driver_test.go b/drivers/gpio/relay_driver_test.go index ce8c9ef93..8003a32b2 100644 --- a/drivers/gpio/relay_driver_test.go +++ b/drivers/gpio/relay_driver_test.go @@ -15,10 +15,10 @@ func (l *RelayDriver) High() bool { return l.high } func initTestRelayDriver() *RelayDriver { a := newGpioTestAdaptor() - a.testAdaptorDigitalWrite = func() (err error) { + a.testAdaptorDigitalWrite = func(string, byte) (err error) { return nil } - a.testAdaptorPwmWrite = func() (err error) { + a.testAdaptorPwmWrite = func(string, byte) (err error) { return nil } return NewRelayDriver(a, "1") diff --git a/drivers/gpio/rgb_led_driver_test.go b/drivers/gpio/rgb_led_driver_test.go index 0b89efeae..46d186651 100644 --- a/drivers/gpio/rgb_led_driver_test.go +++ b/drivers/gpio/rgb_led_driver_test.go @@ -13,10 +13,10 @@ var _ gobot.Driver = (*RgbLedDriver)(nil) func initTestRgbLedDriver() *RgbLedDriver { a := newGpioTestAdaptor() - a.testAdaptorDigitalWrite = func() (err error) { + a.testAdaptorDigitalWrite = func(string, byte) (err error) { return nil } - a.testAdaptorPwmWrite = func() (err error) { + a.testAdaptorPwmWrite = func(string, byte) (err error) { return nil } return NewRgbLedDriver(a, "1", "2", "3") @@ -34,10 +34,10 @@ func TestRgbLedDriver(t *testing.T) { gobottest.Assert(t, d.BluePin(), "3") gobottest.Refute(t, d.Connection(), nil) - a.testAdaptorDigitalWrite = func() (err error) { + a.testAdaptorDigitalWrite = func(string, byte) (err error) { return errors.New("write error") } - a.testAdaptorPwmWrite = func() (err error) { + a.testAdaptorPwmWrite = func(string, byte) (err error) { return errors.New("pwm error") } @@ -79,7 +79,7 @@ func TestRgbLedDriverSetLevel(t *testing.T) { gobottest.Assert(t, d.SetLevel("1", 150), nil) d = NewRgbLedDriver(a, "1", "2", "3") - a.testAdaptorPwmWrite = func() (err error) { + a.testAdaptorPwmWrite = func(string, byte) (err error) { err = errors.New("pwm error") return } diff --git a/drivers/gpio/servo_driver_test.go b/drivers/gpio/servo_driver_test.go index 1973634d0..e44bacb51 100644 --- a/drivers/gpio/servo_driver_test.go +++ b/drivers/gpio/servo_driver_test.go @@ -24,7 +24,7 @@ func TestServoDriver(t *testing.T) { gobottest.Assert(t, d.Pin(), "1") gobottest.Refute(t, d.Connection(), nil) - a.testAdaptorServoWrite = func() (err error) { + a.testAdaptorServoWrite = func(string, byte) (err error) { return errors.New("pwm error") }