gobot.io/x/gobot/v2@v2.1.0/platforms/audio/audio_driver_test.go (about) 1 // Based on aplay audio adaptor written by @colemanserious (https://github.com/colemanserious) 2 3 package audio 4 5 import ( 6 "os/exec" 7 "strings" 8 "testing" 9 10 "gobot.io/x/gobot/v2" 11 "gobot.io/x/gobot/v2/gobottest" 12 ) 13 14 var _ gobot.Driver = (*Driver)(nil) 15 16 func TestAudioDriver(t *testing.T) { 17 d := NewDriver(NewAdaptor(), "../../examples/laser.mp3") 18 19 gobottest.Assert(t, d.Filename(), "../../examples/laser.mp3") 20 21 gobottest.Refute(t, d.Connection(), nil) 22 23 gobottest.Assert(t, d.Start(), nil) 24 25 gobottest.Assert(t, d.Halt(), nil) 26 } 27 28 func TestAudioDriverName(t *testing.T) { 29 d := NewDriver(NewAdaptor(), "") 30 gobottest.Assert(t, strings.HasPrefix(d.Name(), "Audio"), true) 31 d.SetName("NewName") 32 gobottest.Assert(t, d.Name(), "NewName") 33 } 34 35 func TestAudioDriverSoundWithNoFilename(t *testing.T) { 36 d := NewDriver(NewAdaptor(), "") 37 38 errors := d.Sound("") 39 gobottest.Assert(t, errors[0].Error(), "Requires filename for audio file.") 40 } 41 42 func TestAudioDriverSoundWithDefaultFilename(t *testing.T) { 43 execCommand = gobottest.ExecCommand 44 defer func() { execCommand = exec.Command }() 45 46 d := NewDriver(NewAdaptor(), "../../examples/laser.mp3") 47 48 errors := d.Play() 49 gobottest.Assert(t, len(errors), 0) 50 }