[audio] Add additional test coverage for audio adaptor

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-05-24 17:57:59 -07:00
parent 9aad23b3c3
commit 7314d73fd6
2 changed files with 31 additions and 10 deletions

View File

@ -30,7 +30,6 @@ func (a *AudioAdaptor) Connect() []error { return nil }
func (a *AudioAdaptor) Finalize() []error { return nil }
func (a *AudioAdaptor) Sound(fileName string) []error {
var errorsList []error
if fileName == "" {
@ -47,15 +46,10 @@ func (a *AudioAdaptor) Sound(fileName string) []error {
}
// command to play audio file based on file type
fileType := path.Ext(fileName)
var commandName string
if fileType == ".mp3" {
commandName = "mpg123"
} else if fileType == ".wav" {
commandName = "aplay"
} else {
log.Println("Unknown filetype for audio file.")
errorsList = append(errorsList, errors.New("Unknown filetype for audio file."))
commandName, err := CommandName(fileName)
if err != nil {
log.Println(err)
errorsList = append(errorsList, err)
return errorsList
}
@ -70,3 +64,14 @@ func (a *AudioAdaptor) Sound(fileName string) []error {
// Need to return to fulfill function sig, even though returning an empty
return nil
}
func CommandName(fileName string) (commandName string, err error) {
fileType := path.Ext(fileName)
if fileType == ".mp3" {
return "mpg123", nil
} else if fileType == ".wav" {
return "aplay", nil
} else {
return "", errors.New("Unknown filetype for audio file.")
}
}

View File

@ -16,3 +16,19 @@ func TestAudioAdaptor(t *testing.T) {
gobottest.Assert(t, len(a.Finalize()), 0)
}
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.")
}