forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfrc522_driver_test.go
44 lines (38 loc) · 1.13 KB
/
mfrc522_driver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package spi
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"gobot.io/x/gobot/v2"
)
// this ensures that the implementation is based on spi.Driver, which implements the gobot.Driver
// and tests all implementations, so no further tests needed here for gobot.Driver interface
var _ gobot.Driver = (*MFRC522Driver)(nil)
func initTestMFRC522DriverWithStubbedAdaptor() (*MFRC522Driver, *spiTestAdaptor) {
a := newSpiTestAdaptor()
d := NewMFRC522Driver(a)
if err := d.Start(); err != nil {
panic(err)
}
// reset the written bytes during Start()
a.spi.Reset()
return d, a
}
func TestNewMFRC522Driver(t *testing.T) {
var di interface{} = NewMFRC522Driver(newSpiTestAdaptor())
d, ok := di.(*MFRC522Driver)
if !ok {
t.Errorf("NewMFRC522Driver() should have returned a *MFRC522Driver")
}
assert.NotNil(t, d.Driver)
assert.True(t, strings.HasPrefix(d.Name(), "MFRC522"))
}
func TestMFRC522WriteByteData(t *testing.T) {
// arrange
d, a := initTestMFRC522DriverWithStubbedAdaptor()
// act
err := d.connection.WriteByteData(0x00, 0x00)
// assert
assert.NoError(t, err)
assert.Equal(t, []byte{0x00, 0x00}, a.spi.Written())
}