gaper/runner_test.go

50 lines
1.1 KiB
Go
Raw Normal View History

package main
import (
"bytes"
2018-06-20 20:40:09 -05:00
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRunnerSuccessRun(t *testing.T) {
stdout := bytes.NewBufferString("")
stderr := bytes.NewBufferString("")
pArgs := []string{}
bin := filepath.Join("testdata", "print-gaper")
if runtime.GOOS == OSWindows {
bin += ".bat"
}
runner := NewRunner(stdout, stderr, bin, pArgs)
cmd, err := runner.Run()
assert.Nil(t, err, "error running binary")
assert.NotNil(t, cmd.Process, "process has not started")
errCmd := <-runner.Errors()
assert.Nil(t, errCmd, "async error running binary")
2018-06-20 21:15:58 -05:00
assert.Contains(t, stdout.String(), "Gaper Test Message")
}
2018-06-20 20:40:09 -05:00
func TestRunnerSuccessKill(t *testing.T) {
bin := filepath.Join("testdata", "print-gaper")
if runtime.GOOS == OSWindows {
bin += ".bat"
}
runner := NewRunner(os.Stdout, os.Stderr, bin, nil)
_, err := runner.Run()
assert.Nil(t, err, "error running binary")
err = runner.Kill()
assert.Nil(t, err, "error killing program")
errCmd := <-runner.Errors()
assert.NotNil(t, errCmd, "kill program")
}