Skip to content

Commit

Permalink
test(all): substitude assert.Errorf by assert.Error (hybridgroup#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas authored Oct 21, 2023
1 parent a4a8d10 commit ee4368b
Show file tree
Hide file tree
Showing 80 changed files with 306 additions and 281 deletions.
6 changes: 3 additions & 3 deletions drivers/gpio/buzzer_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestBuzzerDriverOnError(t *testing.T) {
return errors.New("write error")
})

assert.Errorf(t, d.On(), "write error")
assert.Error(t, d.On(), "write error")
}

func TestBuzzerDriverOffError(t *testing.T) {
Expand All @@ -67,7 +67,7 @@ func TestBuzzerDriverOffError(t *testing.T) {
return errors.New("write error")
})

assert.Errorf(t, d.Off(), "write error")
assert.Error(t, d.Off(), "write error")
}

func TestBuzzerDriverToneError(t *testing.T) {
Expand All @@ -77,5 +77,5 @@ func TestBuzzerDriverToneError(t *testing.T) {
return errors.New("write error")
})

assert.Errorf(t, d.Tone(100, 0.01), "write error")
assert.Error(t, d.Tone(100, 0.01), "write error")
}
18 changes: 9 additions & 9 deletions drivers/gpio/direct_pin_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func TestDirectPinDriver(t *testing.T) {
assert.Nil(t, ret["err"])

err = d.Command("DigitalWrite")(map[string]interface{}{"level": "1"})
assert.Errorf(t, err.(error), "write error")
assert.Error(t, err.(error), "write error")

err = d.Command("PwmWrite")(map[string]interface{}{"level": "1"})
assert.Errorf(t, err.(error), "write error")
assert.Error(t, err.(error), "write error")

err = d.Command("ServoWrite")(map[string]interface{}{"level": "1"})
assert.Errorf(t, err.(error), "write error")
assert.Error(t, err.(error), "write error")
}

func TestDirectPinDriverStart(t *testing.T) {
Expand All @@ -74,7 +74,7 @@ func TestDirectPinDriverOff(t *testing.T) {
func TestDirectPinDriverOffNotSupported(t *testing.T) {
a := &gpioTestBareAdaptor{}
d := NewDirectPinDriver(a, "1")
assert.Errorf(t, d.Off(), "DigitalWrite is not supported by this platform")
assert.Error(t, d.Off(), "DigitalWrite is not supported by this platform")
}

func TestDirectPinDriverOn(t *testing.T) {
Expand All @@ -91,7 +91,7 @@ func TestDirectPinDriverOnError(t *testing.T) {
func TestDirectPinDriverOnNotSupported(t *testing.T) {
a := &gpioTestBareAdaptor{}
d := NewDirectPinDriver(a, "1")
assert.Errorf(t, d.On(), "DigitalWrite is not supported by this platform")
assert.Error(t, d.On(), "DigitalWrite is not supported by this platform")
}

func TestDirectPinDriverDigitalWrite(t *testing.T) {
Expand All @@ -103,7 +103,7 @@ func TestDirectPinDriverDigitalWrite(t *testing.T) {
func TestDirectPinDriverDigitalWriteNotSupported(t *testing.T) {
a := &gpioTestBareAdaptor{}
d := NewDirectPinDriver(a, "1")
assert.Errorf(t, d.DigitalWrite(1), "DigitalWrite is not supported by this platform")
assert.Error(t, d.DigitalWrite(1), "DigitalWrite is not supported by this platform")
}

func TestDirectPinDriverDigitalWriteError(t *testing.T) {
Expand All @@ -122,7 +122,7 @@ func TestDirectPinDriverDigitalReadNotSupported(t *testing.T) {
a := &gpioTestBareAdaptor{}
d := NewDirectPinDriver(a, "1")
_, e := d.DigitalRead()
assert.Errorf(t, e, "DigitalRead is not supported by this platform")
assert.Error(t, e, "DigitalRead is not supported by this platform")
}

func TestDirectPinDriverPwmWrite(t *testing.T) {
Expand All @@ -134,7 +134,7 @@ func TestDirectPinDriverPwmWrite(t *testing.T) {
func TestDirectPinDriverPwmWriteNotSupported(t *testing.T) {
a := &gpioTestBareAdaptor{}
d := NewDirectPinDriver(a, "1")
assert.Errorf(t, d.PwmWrite(1), "PwmWrite is not supported by this platform")
assert.Error(t, d.PwmWrite(1), "PwmWrite is not supported by this platform")
}

func TestDirectPinDriverPwmWriteError(t *testing.T) {
Expand All @@ -151,7 +151,7 @@ func TestDirectPinDriverServoWrite(t *testing.T) {
func TestDirectPinDriverServoWriteNotSupported(t *testing.T) {
a := &gpioTestBareAdaptor{}
d := NewDirectPinDriver(a, "1")
assert.Errorf(t, d.ServoWrite(1), "ServoWrite is not supported by this platform")
assert.Error(t, d.ServoWrite(1), "ServoWrite is not supported by this platform")
}

func TestDirectPinDriverServoWriteError(t *testing.T) {
Expand Down
18 changes: 9 additions & 9 deletions drivers/gpio/hd44780_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestHD44780DriverStartError(t *testing.T) {
D7: "",
}
d = NewHD44780Driver(a, 2, 16, HD44780_4BITMODE, "13", "15", pins)
assert.Errorf(t, d.Start(), "Initialization error")
assert.Error(t, d.Start(), "Initialization error")

pins = HD44780DataPin{
D0: "31",
Expand All @@ -106,7 +106,7 @@ func TestHD44780DriverStartError(t *testing.T) {
D7: "",
}
d = NewHD44780Driver(a, 2, 16, HD44780_8BITMODE, "13", "15", pins)
assert.Errorf(t, d.Start(), "Initialization error")
assert.Error(t, d.Start(), "Initialization error")
}

func TestHD44780DriverWrite(t *testing.T) {
Expand All @@ -130,14 +130,14 @@ func TestHD44780DriverWriteError(t *testing.T) {
return errors.New("write error")
}
_ = d.Start()
assert.Errorf(t, d.Write("hello gobot"), "write error")
assert.Error(t, d.Write("hello gobot"), "write error")

d, a = initTestHD44780Driver8BitModeWithStubbedAdaptor()
a.testAdaptorDigitalWrite = func(string, byte) (err error) {
return errors.New("write error")
}
_ = d.Start()
assert.Errorf(t, d.Write("hello gobot"), "write error")
assert.Error(t, d.Write("hello gobot"), "write error")
}

func TestHD44780DriverClear(t *testing.T) {
Expand All @@ -158,10 +158,10 @@ func TestHD44780DriverSetCursor(t *testing.T) {
func TestHD44780DriverSetCursorInvalid(t *testing.T) {
d := initTestHD44780Driver()

assert.Errorf(t, d.SetCursor(-1, 3), "Invalid position value (-1, 3), range (1, 15)")
assert.Errorf(t, d.SetCursor(2, 3), "Invalid position value (2, 3), range (1, 15)")
assert.Errorf(t, d.SetCursor(0, -1), "Invalid position value (0, -1), range (1, 15)")
assert.Errorf(t, d.SetCursor(0, 16), "Invalid position value (0, 16), range (1, 15)")
assert.Error(t, d.SetCursor(-1, 3), "Invalid position value (-1, 3), range (1, 15)")
assert.Error(t, d.SetCursor(2, 3), "Invalid position value (2, 3), range (1, 15)")
assert.Error(t, d.SetCursor(0, -1), "Invalid position value (0, -1), range (1, 15)")
assert.Error(t, d.SetCursor(0, 16), "Invalid position value (0, 16), range (1, 15)")
}

func TestHD44780DriverDisplayOn(t *testing.T) {
Expand Down Expand Up @@ -233,5 +233,5 @@ func TestHD44780DriverCreateChar(t *testing.T) {
func TestHD44780DriverCreateCharError(t *testing.T) {
d := initTestHD44780Driver()
charMap := [8]byte{1, 2, 3, 4, 5, 6, 7, 8}
assert.Errorf(t, d.CreateChar(8, charMap), "can't set a custom character at a position greater than 7")
assert.Error(t, d.CreateChar(8, charMap), "can't set a custom character at a position greater than 7")
}
10 changes: 5 additions & 5 deletions drivers/gpio/led_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ func TestLedDriver(t *testing.T) {
}

err = d.Command("Toggle")(nil)
assert.Errorf(t, err.(error), "write error")
assert.Error(t, err.(error), "write error")

err = d.Command("On")(nil)
assert.Errorf(t, err.(error), "write error")
assert.Error(t, err.(error), "write error")

err = d.Command("Off")(nil)
assert.Errorf(t, err.(error), "write error")
assert.Error(t, err.(error), "write error")

err = d.Command("Brightness")(map[string]interface{}{"level": 100.0})
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")
}

func TestLedDriverStart(t *testing.T) {
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestLedDriverBrightness(t *testing.T) {
err = errors.New("pwm error")
return
}
assert.Errorf(t, d.Brightness(150), "pwm error")
assert.Error(t, d.Brightness(150), "pwm error")
}

func TestLEDDriverDefaultName(t *testing.T) {
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 @@ -42,16 +42,16 @@ func TestRgbLedDriver(t *testing.T) {
}

err = d.Command("Toggle")(nil)
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")

err = d.Command("On")(nil)
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")

err = d.Command("Off")(nil)
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")

err = d.Command("SetRGB")(map[string]interface{}{"r": 0xff, "g": 0xff, "b": 0xff})
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")
}

func TestRgbLedDriverStart(t *testing.T) {
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestRgbLedDriverSetLevel(t *testing.T) {
err = errors.New("pwm error")
return
}
assert.Errorf(t, d.SetLevel("1", 150), "pwm error")
assert.Error(t, d.SetLevel("1", 150), "pwm error")
}

func TestRgbLedDriverDefaultName(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions drivers/gpio/servo_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func TestServoDriver(t *testing.T) {
}

err = d.Command("Min")(nil)
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")

err = d.Command("Center")(nil)
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")

err = d.Command("Max")(nil)
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")

err = d.Command("Move")(map[string]interface{}{"angle": 100.0})
assert.Errorf(t, err.(error), "pwm error")
assert.Error(t, err.(error), "pwm error")
}

func TestServoDriverStart(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/stepper_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestStepperDriverDefaultDirection(t *testing.T) {
func TestStepperDriverInvalidDirection(t *testing.T) {
d := initStepperMotorDriver()
err := d.SetDirection("reverse")
assert.Errorf(t, err, "Invalid direction. Value should be forward or backward")
assert.Error(t, err, "Invalid direction. Value should be forward or backward")
}

func TestStepperDriverMoveForward(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/i2c/adafruit1109_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func TestAdafruit1109StartWriteErr(t *testing.T) {
adaptor.i2cWriteImpl = func([]byte) (int, error) {
return 0, errors.New("write error")
}
assert.Errorf(t, d.Start(), "write error")
assert.Error(t, d.Start(), "write error")
}

func TestAdafruit1109StartReadErr(t *testing.T) {
d, adaptor := initTestAdafruit1109WithStubbedAdaptor()
adaptor.i2cReadImpl = func([]byte) (int, error) {
return 0, errors.New("read error")
}
assert.Errorf(t, d.Start(), "MCP write-read: MCP write-ReadByteData(reg=0): read error")
assert.Error(t, d.Start(), "MCP write-read: MCP write-ReadByteData(reg=0): read error")
}

func TestAdafruit1109Halt(t *testing.T) {
Expand Down
18 changes: 9 additions & 9 deletions drivers/i2c/adafruit_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ func TestAdafruitMotorHatDriverStartWriteError(t *testing.T) {
adaptor.i2cWriteImpl = func([]byte) (int, error) {
return 0, errors.New("write error")
}
assert.Errorf(t, d.Start(), "write error")
assert.Error(t, d.Start(), "write error")
}

func TestAdafruitMotorHatDriverStartReadError(t *testing.T) {
d, adaptor := initTestAdafruitMotorHatDriverWithStubbedAdaptor()
adaptor.i2cReadImpl = func([]byte) (int, error) {
return 0, errors.New("read error")
}
assert.Errorf(t, d.Start(), "read error")
assert.Error(t, d.Start(), "read error")
}

func TestAdafruitMotorHatDriverStartConnectError(t *testing.T) {
d, adaptor := initTestAdafruitMotorHatDriverWithStubbedAdaptor()
adaptor.Testi2cConnectErr(true)
assert.Errorf(t, d.Start(), "Invalid i2c connection")
assert.Error(t, d.Start(), "Invalid i2c connection")
}

func TestAdafruitMotorHatDriverHalt(t *testing.T) {
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestAdafruitMotorHatDriverSetServoMotorFreqError(t *testing.T) {
}

freq := 60.0
assert.Errorf(t, ada.SetServoMotorFreq(freq), "write error")
assert.Error(t, ada.SetServoMotorFreq(freq), "write error")
}

func TestAdafruitMotorHatDriverSetServoMotorPulse(t *testing.T) {
Expand All @@ -122,7 +122,7 @@ func TestAdafruitMotorHatDriverSetServoMotorPulseError(t *testing.T) {
var channel byte = 7
var on int32 = 1234
var off int32 = 4321
assert.Errorf(t, ada.SetServoMotorPulse(channel, on, off), "write error")
assert.Error(t, ada.SetServoMotorPulse(channel, on, off), "write error")
}

func TestAdafruitMotorHatDriverSetDCMotorSpeed(t *testing.T) {
Expand All @@ -144,7 +144,7 @@ func TestAdafruitMotorHatDriverSetDCMotorSpeedError(t *testing.T) {
return 0, errors.New("write error")
}

assert.Errorf(t, ada.SetDCMotorSpeed(1, 255), "write error")
assert.Error(t, ada.SetDCMotorSpeed(1, 255), "write error")
}

func TestAdafruitMotorHatDriverRunDCMotor(t *testing.T) {
Expand All @@ -166,9 +166,9 @@ func TestAdafruitMotorHatDriverRunDCMotorError(t *testing.T) {
}

dcMotor := 1
assert.Errorf(t, ada.RunDCMotor(dcMotor, AdafruitForward), "write error")
assert.Errorf(t, ada.RunDCMotor(dcMotor, AdafruitBackward), "write error")
assert.Errorf(t, ada.RunDCMotor(dcMotor, AdafruitRelease), "write error")
assert.Error(t, ada.RunDCMotor(dcMotor, AdafruitForward), "write error")
assert.Error(t, ada.RunDCMotor(dcMotor, AdafruitBackward), "write error")
assert.Error(t, ada.RunDCMotor(dcMotor, AdafruitRelease), "write error")
}

func TestAdafruitMotorHatDriverSetStepperMotorSpeed(t *testing.T) {
Expand Down
18 changes: 9 additions & 9 deletions drivers/i2c/ads1x15_driver_1015_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ func TestADS1x15AnalogReadError(t *testing.T) {
}

_, err := d.AnalogRead("0")
assert.Errorf(t, err, "read error")
assert.Error(t, err, "read error")
}

func TestADS1x15AnalogReadInvalidPin(t *testing.T) {
d, _ := initTestADS1015DriverWithStubbedAdaptor()

_, err := d.AnalogRead("99")
assert.Errorf(t, err, "Invalid channel (99), must be between 0 and 3")
assert.Error(t, err, "Invalid channel (99), must be between 0 and 3")
}

func TestADS1x15AnalogReadWriteError(t *testing.T) {
Expand All @@ -133,41 +133,41 @@ func TestADS1x15AnalogReadWriteError(t *testing.T) {
}

_, err := d.AnalogRead("0")
assert.Errorf(t, err, "write error")
assert.Error(t, err, "write error")

_, err = d.AnalogRead("0-1")
assert.Errorf(t, err, "write error")
assert.Error(t, err, "write error")

_, err = d.AnalogRead("2-3")
assert.Errorf(t, err, "write error")
assert.Error(t, err, "write error")
}

func TestADS1x15ReadInvalidChannel(t *testing.T) {
d, _ := initTestADS1015DriverWithStubbedAdaptor()

_, err := d.Read(9, 1, 1600)
assert.Errorf(t, err, "Invalid channel (9), must be between 0 and 3")
assert.Error(t, err, "Invalid channel (9), must be between 0 and 3")
}

func TestADS1x15ReadInvalidGain(t *testing.T) {
d, _ := initTestADS1015DriverWithStubbedAdaptor()

_, err := d.Read(0, 8, 1600)
assert.Errorf(t, err, "Gain (8) must be one of: [0 1 2 3 4 5 6 7]")
assert.Error(t, err, "Gain (8) must be one of: [0 1 2 3 4 5 6 7]")
}

func TestADS1x15ReadInvalidDataRate(t *testing.T) {
d, _ := initTestADS1015DriverWithStubbedAdaptor()

_, err := d.Read(0, 1, 321)
assert.Errorf(t, err, "Invalid data rate (321). Accepted values: [128 250 490 920 1600 2400 3300]")
assert.Error(t, err, "Invalid data rate (321). Accepted values: [128 250 490 920 1600 2400 3300]")
}

func TestADS1x15ReadDifferenceInvalidChannel(t *testing.T) {
d, _ := initTestADS1015DriverWithStubbedAdaptor()

_, err := d.ReadDifference(9, 1, 1600)
assert.Errorf(t, err, "Invalid channel (9), must be between 0 and 3")
assert.Error(t, err, "Invalid channel (9), must be between 0 and 3")
}

func TestADS1015_rawRead(t *testing.T) {
Expand Down
Loading

0 comments on commit ee4368b

Please sign in to comment.