gaper/runner_test.go

51 lines
1.1 KiB
Go

package gaper
import (
"bytes"
"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")
assert.Contains(t, stdout.String(), "Gaper Test Message")
assert.Equal(t, stderr.String(), "")
}
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")
}