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 0b7b1ec commit faf506d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions sysfs/digital_pin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,41 @@ func TestDigitalPin(t *testing.T) {
err = pin.Export()
gobottest.Assert(t, err.(*os.PathError).Err, errors.New("write error"))
}

func TestDigitalPinExportError(t *testing.T) {
fs := NewMockFilesystem([]string{
"/sys/class/gpio/export",
"/sys/class/gpio/unexport",
"/sys/class/gpio/gpio10/value",
"/sys/class/gpio/gpio10/direction",
})

SetFilesystem(fs)

pin := NewDigitalPin(10, "custom").(*digitalPin)
writeFile = func(File, []byte) (int, error) {
return 0, &os.PathError{Err: syscall.EBUSY}
}

err := pin.Export()
gobottest.Refute(t, err, nil)
}

func TestDigitalPinUnexportError(t *testing.T) {
fs := NewMockFilesystem([]string{
"/sys/class/gpio/export",
"/sys/class/gpio/unexport",
"/sys/class/gpio/gpio10/value",
"/sys/class/gpio/gpio10/direction",
})

SetFilesystem(fs)

pin := NewDigitalPin(10, "custom").(*digitalPin)
writeFile = func(File, []byte) (int, error) {
return 0, &os.PathError{Err: syscall.EBUSY}
}

err := pin.Unexport()
gobottest.Refute(t, err, nil)
}

0 comments on commit faf506d

Please sign in to comment.