[audio] Test coverage for exexcution of audio adaptor
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
c111636c32
commit
970324cea6
|
@ -53,8 +53,7 @@ func (a *AudioAdaptor) Sound(fileName string) []error {
|
|||
return errorsList
|
||||
}
|
||||
|
||||
cmd := exec.Command(commandName, fileName)
|
||||
err = cmd.Start()
|
||||
err = RunCommand(commandName, fileName)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
errorsList = append(errorsList, err)
|
||||
|
@ -75,3 +74,11 @@ func CommandName(fileName string) (commandName string, err error) {
|
|||
return "", errors.New("Unknown filetype for audio file.")
|
||||
}
|
||||
}
|
||||
|
||||
var execCommand = exec.Command
|
||||
|
||||
func RunCommand(audioCommand string, filename string) error {
|
||||
cmd := execCommand(audioCommand, filename)
|
||||
err := cmd.Start()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
package audio
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/hybridgroup/gobot/gobottest"
|
||||
|
@ -46,3 +48,22 @@ func TestAudioAdaptorSoundWithNonexistingFilename(t *testing.T) {
|
|||
errors := a.Sound("doesnotexist.mp3")
|
||||
gobottest.Assert(t, errors[0].Error(), "stat doesnotexist.mp3: no such file or directory")
|
||||
}
|
||||
|
||||
func fakeExecCommand(command string, args ...string) *exec.Cmd {
|
||||
cs := []string{"-test.run=TestHelperProcess", "--", command}
|
||||
cs = append(cs, args...)
|
||||
cmd := exec.Command(os.Args[0], cs...)
|
||||
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func TestAudioAdaptorSoundWithValidMP3Filename(t *testing.T) {
|
||||
execCommand = fakeExecCommand
|
||||
|
||||
a := NewAudioAdaptor("tester")
|
||||
defer func() { execCommand = exec.Command }()
|
||||
|
||||
errors := a.Sound("../../examples/laser.mp3")
|
||||
|
||||
gobottest.Assert(t, len(errors), 0)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue