Skip to content

Commit

Permalink
Update function signatures in gpioTestAdaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartleeks committed Mar 30, 2020
1 parent 5541dcd commit 66af258
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 60 deletions.
12 changes: 6 additions & 6 deletions drivers/gpio/button_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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
})
Expand All @@ -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
})
Expand All @@ -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
})
Expand All @@ -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
})
Expand All @@ -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
})
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/buzzer_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

Expand All @@ -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")
})

Expand All @@ -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")
})

Expand Down
8 changes: 4 additions & 4 deletions drivers/gpio/direct_pin_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/grove_drivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
50 changes: 25 additions & 25 deletions drivers/gpio/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
},
}
Expand Down
10 changes: 5 additions & 5 deletions drivers/gpio/led_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}

Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/gpio/makey_button_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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
})
Expand All @@ -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
})
Expand All @@ -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
})
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/pir_motion_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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
})
Expand All @@ -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
})
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/relay_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions drivers/gpio/rgb_led_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/servo_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 66af258

Please sign in to comment.