2023-01-06 02:04:32 +08:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-10-20 16:27:09 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-01-06 02:04:32 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGpioSpi_isSupported(t *testing.T) {
|
|
|
|
// arrange
|
|
|
|
gsa := gpioSpiAccess{}
|
|
|
|
// act
|
|
|
|
got := gsa.isSupported()
|
|
|
|
// assert
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.True(t, got)
|
2023-01-06 02:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPeriphioSpi_isSupported(t *testing.T) {
|
2023-10-21 02:50:42 +08:00
|
|
|
tests := map[string]struct {
|
2023-01-06 02:04:32 +08:00
|
|
|
mockPaths []string
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
"supported": {
|
|
|
|
mockPaths: []string{"/dev/spidev0.0", "/dev/spidev1.0"},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
"not_supported": {
|
|
|
|
mockPaths: []string{"/sys/class/gpio/"},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for name, tc := range tests {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
// arrange
|
|
|
|
fs := newMockFilesystem(tc.mockPaths)
|
|
|
|
psa := periphioSpiAccess{fs: fs}
|
|
|
|
// act
|
|
|
|
got := psa.isSupported()
|
|
|
|
// assert
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.Equal(t, tc.want, got)
|
2023-01-06 02:04:32 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|