gobot.io/x/gobot/v2@v2.1.0/drivers/spi/apa102_test.go (about) 1 package spi 2 3 import ( 4 "image/color" 5 "strings" 6 "testing" 7 8 "gobot.io/x/gobot/v2" 9 "gobot.io/x/gobot/v2/gobottest" 10 ) 11 12 // this ensures that the implementation is based on spi.Driver, which implements the gobot.Driver 13 // and tests all implementations, so no further tests needed here for gobot.Driver interface 14 var _ gobot.Driver = (*APA102Driver)(nil) 15 16 func initTestAPA102DriverWithStubbedAdaptor() *APA102Driver { 17 a := newSpiTestAdaptor() 18 d := NewAPA102Driver(a, 10, 31) 19 if err := d.Start(); err != nil { 20 panic(err) 21 } 22 return d 23 } 24 25 func TestNewAPA102Driver(t *testing.T) { 26 var di interface{} = NewAPA102Driver(newSpiTestAdaptor(), 10, 31) 27 d, ok := di.(*APA102Driver) 28 if !ok { 29 t.Errorf("NewAPA102Driver() should have returned a *APA102Driver") 30 } 31 gobottest.Refute(t, d.Driver, nil) 32 gobottest.Assert(t, strings.HasPrefix(d.Name(), "APA102"), true) 33 } 34 35 func TestDriverLEDs(t *testing.T) { 36 d := initTestAPA102DriverWithStubbedAdaptor() 37 38 d.SetRGBA(0, color.RGBA{255, 255, 255, 15}) 39 d.SetRGBA(1, color.RGBA{255, 255, 255, 15}) 40 d.SetRGBA(2, color.RGBA{255, 255, 255, 15}) 41 d.SetRGBA(3, color.RGBA{255, 255, 255, 15}) 42 43 gobottest.Assert(t, d.Draw(), nil) 44 }