forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_driver_test.go
50 lines (35 loc) · 1.16 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
// Based on aplay audio adaptor written by @colemanserious (https://github.com/colemanserious)
package audio
import (
"os/exec"
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
)
var _ gobot.Driver = (*Driver)(nil)
func TestAudioDriver(t *testing.T) {
d := NewDriver(NewAdaptor(), "../../examples/laser.mp3")
gobottest.Assert(t, d.Filename(), "../../examples/laser.mp3")
gobottest.Refute(t, d.Connection(), nil)
gobottest.Assert(t, d.Start(), nil)
gobottest.Assert(t, d.Halt(), nil)
}
func TestAudioDriverName(t *testing.T) {
d := NewDriver(NewAdaptor(), "")
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Audio"), true)
d.SetName("NewName")
gobottest.Assert(t, d.Name(), "NewName")
}
func TestAudioDriverSoundWithNoFilename(t *testing.T) {
d := NewDriver(NewAdaptor(), "")
errors := d.Sound("")
gobottest.Assert(t, errors[0].Error(), "Requires filename for audio file.")
}
func TestAudioDriverSoundWithDefaultFilename(t *testing.T) {
execCommand = gobottest.ExecCommand
defer func() { execCommand = exec.Command }()
d := NewDriver(NewAdaptor(), "../../examples/laser.mp3")
errors := d.Play()
gobottest.Assert(t, len(errors), 0)
}