gobot.io/x/gobot/v2@v2.1.0/drivers/spi/spi_driver_test.go (about) 1 package spi 2 3 import ( 4 "strings" 5 "testing" 6 7 "gobot.io/x/gobot/v2" 8 "gobot.io/x/gobot/v2/gobottest" 9 ) 10 11 var _ gobot.Driver = (*Driver)(nil) 12 13 func initTestDriverWithStubbedAdaptor() (*Driver, *spiTestAdaptor) { 14 a := newSpiTestAdaptor() 15 d := NewDriver(a, "SPI_BASIC") 16 if err := d.Start(); err != nil { 17 panic(err) 18 } 19 return d, a 20 } 21 22 func TestNewDriver(t *testing.T) { 23 var di interface{} = NewDriver(newSpiTestAdaptor(), "SPI_BASIC") 24 d, ok := di.(*Driver) 25 if !ok { 26 t.Errorf("NewDriver() should have returned a *Driver") 27 } 28 gobottest.Assert(t, strings.HasPrefix(d.Name(), "SPI_BASIC"), true) 29 } 30 31 func TestStart(t *testing.T) { 32 d := NewDriver(newSpiTestAdaptor(), "SPI_BASIC") 33 gobottest.Assert(t, d.Start(), nil) 34 } 35 36 func TestHalt(t *testing.T) { 37 d, _ := initTestDriverWithStubbedAdaptor() 38 gobottest.Assert(t, d.Halt(), nil) 39 } 40 41 func TestSetName(t *testing.T) { 42 // arrange 43 d, _ := initTestDriverWithStubbedAdaptor() 44 // act 45 d.SetName("TESTME") 46 // assert 47 gobottest.Assert(t, d.Name(), "TESTME") 48 } 49 50 func TestConnection(t *testing.T) { 51 d, _ := initTestDriverWithStubbedAdaptor() 52 gobottest.Refute(t, d.Connection(), nil) 53 }