-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathaudio_driver_test.go
52 lines (36 loc) · 1.15 KB
/
audio_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
45
46
47
48
49
50
51
52
// Based on aplay audio adaptor written by @colemanserious (https://github.com/colemanserious)
package audio
import (
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gobot.io/x/gobot/v2"
)
var _ gobot.Driver = (*Driver)(nil)
func TestAudioDriver(t *testing.T) {
d := NewDriver(NewAdaptor(), "../../examples/laser.mp3")
assert.Equal(t, "../../examples/laser.mp3", d.Filename())
assert.NotNil(t, d.Connection())
require.NoError(t, d.Start())
require.NoError(t, d.Halt())
}
func TestAudioDriverName(t *testing.T) {
d := NewDriver(NewAdaptor(), "")
assert.True(t, strings.HasPrefix(d.Name(), "Audio"))
d.SetName("NewName")
assert.Equal(t, "NewName", d.Name())
}
func TestAudioDriverSoundWithNoFilename(t *testing.T) {
d := NewDriver(NewAdaptor(), "")
errors := d.Sound("")
require.ErrorContains(t, errors[0], "requires filename for audio file")
}
func TestAudioDriverSoundWithDefaultFilename(t *testing.T) {
execCommand = myExecCommand
defer func() { execCommand = exec.Command }()
d := NewDriver(NewAdaptor(), "../../examples/laser.mp3")
errors := d.Play()
assert.Empty(t, errors)
}