Skip to content

Commit

Permalink
sysfs: increase test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Apr 9, 2017
1 parent 92a7419 commit cce6535
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sysfs/i2c_device_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sysfs

import (
"errors"
"os"
"syscall"
"testing"
Expand All @@ -23,9 +24,28 @@ func TestNewI2cDeviceClose(t *testing.T) {
gobottest.Assert(t, i.Close(), nil)
}

func TestNewI2cDeviceQueryFuncError(t *testing.T) {
fs := NewMockFilesystem([]string{
"/dev/i2c-1",
})
SetFilesystem(fs)

SetSyscall(&MockSyscall{
Impl: func(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) {
return 0, 0, 1
},
})

i, err := NewI2cDevice("/dev/i2c-1")
var _ I2cDevice = i

gobottest.Assert(t, err, errors.New("Querying functionality failed with syscall.Errno operation not permitted"))
}

func TestNewI2cDevice(t *testing.T) {
fs := NewMockFilesystem([]string{})
SetFilesystem(fs)
SetSyscall(&MockSyscall{})

i, err := NewI2cDevice(os.DevNull)
gobottest.Assert(t, err.Error(), " : /dev/null: No such file.")
Expand Down

0 comments on commit cce6535

Please sign in to comment.