From 05f7c872e1e3faa0f3c3f367144f15a3acf3efeb Mon Sep 17 00:00:00 2001 From: th002 <29159387@qq.com> Date: Wed, 7 Sep 2016 17:30:35 +0800 Subject: [PATCH] Add PinMode test case Add PinMode test case --- platforms/i2c/mcp23017_driver_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/platforms/i2c/mcp23017_driver_test.go b/platforms/i2c/mcp23017_driver_test.go index cfcac9fb..e02adc57 100644 --- a/platforms/i2c/mcp23017_driver_test.go +++ b/platforms/i2c/mcp23017_driver_test.go @@ -187,6 +187,29 @@ func TestMCP23017DriverReadGPIO(t *testing.T) { gobottest.Assert(t, err, errors.New("Read came back with no data")) } +func TestMCP23017DriverPinMode(t *testing.T) { + mcp, adaptor := initTestMCP23017DriverWithStubbedAdaptor(0) + adaptor.i2cMcpReadImpl = func(a int, b int) ([]byte, error) { + return make([]byte, b), nil + } + adaptor.i2cMcpWriteImpl = func() error { + return nil + } + err := mcp.PinMode(7, 0, "A") + gobottest.Assert(t, err, nil) + + // write error + mcp, adaptor = initTestMCP23017DriverWithStubbedAdaptor(0) + adaptor.i2cMcpReadImpl = func(a int, b int) ([]byte, error) { + return make([]byte, b), nil + } + adaptor.i2cMcpWriteImpl = func() error { + return errors.New("write error") + } + err = mcp.PinMode(7, 0, "A") + gobottest.Assert(t, err, errors.New("write error")) +} + func TestMCP23017DriverSetPullUp(t *testing.T) { mcp, adaptor := initTestMCP23017DriverWithStubbedAdaptor(0) adaptor.i2cMcpReadImpl = func(a int, b int) ([]byte, error) {