From ca3a9bdbda385f70138ce897b926bc7b8b5db3b1 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Mon, 20 Mar 2017 18:21:12 +0100 Subject: [PATCH] i2c: test coverage for Close() Signed-off-by: deadprogram --- drivers/i2c/i2c.go | 4 ++-- drivers/i2c/i2c_test.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/i2c.go b/drivers/i2c/i2c.go index 7a1521c1..aa5184f1 100644 --- a/drivers/i2c/i2c.go +++ b/drivers/i2c/i2c.go @@ -58,7 +58,7 @@ func NewConnection(bus sysfs.I2cDevice, address int) (connection *i2cConnection) // Read data from an i2c device. func (c *i2cConnection) Read(data []byte) (read int, err error) { - if err := c.bus.SetAddress(c.address); err != nil { + if err = c.bus.SetAddress(c.address); err != nil { return 0, err } read, err = c.bus.Read(data) @@ -67,7 +67,7 @@ func (c *i2cConnection) Read(data []byte) (read int, err error) { // Write data to an i2c device. func (c *i2cConnection) Write(data []byte) (written int, err error) { - if err := c.bus.SetAddress(c.address); err != nil { + if err = c.bus.SetAddress(c.address); err != nil { return 0, err } written, err = c.bus.Write(data) diff --git a/drivers/i2c/i2c_test.go b/drivers/i2c/i2c_test.go index a6bb2243..d5a051af 100644 --- a/drivers/i2c/i2c_test.go +++ b/drivers/i2c/i2c_test.go @@ -3,10 +3,11 @@ package i2c import ( "testing" - "gobot.io/x/gobot/gobottest" - "gobot.io/x/gobot/sysfs" "syscall" "unsafe" + + "gobot.io/x/gobot/gobottest" + "gobot.io/x/gobot/sysfs" ) func syscallImpl(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { @@ -39,6 +40,11 @@ func TestI2CAddress(t *testing.T) { gobottest.Assert(t, c.address, 0x66) } +func TestI2CClose(t *testing.T) { + c := NewConnection(initI2CDevice(), 0x06) + gobottest.Assert(t, c.Close(), nil) +} + func TestI2CRead(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) i, _ := c.Read([]byte{})