forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_adaptor_test.go
68 lines (51 loc) · 1.65 KB
/
audio_adaptor_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// 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.Adaptor = (*Adaptor)(nil)
func TestAudioAdaptor(t *testing.T) {
a := NewAdaptor()
gobottest.Assert(t, a.Connect(), nil)
gobottest.Assert(t, a.Finalize(), nil)
}
func TestAudioAdaptorName(t *testing.T) {
a := NewAdaptor()
gobottest.Assert(t, strings.HasPrefix(a.Name(), "Audio"), true)
a.SetName("NewName")
gobottest.Assert(t, a.Name(), "NewName")
}
func TestAudioAdaptorCommandsWav(t *testing.T) {
cmd, _ := CommandName("whatever.wav")
gobottest.Assert(t, cmd, "aplay")
}
func TestAudioAdaptorCommandsMp3(t *testing.T) {
cmd, _ := CommandName("whatever.mp3")
gobottest.Assert(t, cmd, "mpg123")
}
func TestAudioAdaptorCommandsUnknown(t *testing.T) {
cmd, err := CommandName("whatever.unk")
gobottest.Refute(t, cmd, "mpg123")
gobottest.Assert(t, err.Error(), "Unknown filetype for audio file.")
}
func TestAudioAdaptorSoundWithNoFilename(t *testing.T) {
a := NewAdaptor()
errors := a.Sound("")
gobottest.Assert(t, errors[0].Error(), "Requires filename for audio file.")
}
func TestAudioAdaptorSoundWithNonexistingFilename(t *testing.T) {
a := NewAdaptor()
errors := a.Sound("doesnotexist.mp3")
gobottest.Assert(t, errors[0].Error(), "stat doesnotexist.mp3: no such file or directory")
}
func TestAudioAdaptorSoundWithValidMP3Filename(t *testing.T) {
execCommand = gobottest.ExecCommand
a := NewAdaptor()
defer func() { execCommand = exec.Command }()
errors := a.Sound("../../examples/laser.mp3")
gobottest.Assert(t, len(errors), 0)
}