Added Example tests with failure status for ExecAndStream

pull/13/head
Paulo Truta 2021-06-12 14:24:13 +00:00
parent ac8b70976b
commit a1c0529fda
2 changed files with 22 additions and 1 deletions

View File

@ -27,7 +27,7 @@ func ExecAndStream(path string, command string, args []string) {
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err) fmt.Printf("cmd.Run() failed with %s\n", err)
} }
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes()) outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())

View File

@ -30,6 +30,27 @@ func ExampleExecAndStream() {
// err: // err:
} }
func ExampleExecAndStreamExecutableNotFound() {
ExecAndStream("/", "testcommand", []string{"Hello"})
// Output:
// cmd.Run() failed with exec: "testcommand": executable file not found in $PATH
//
// out:
//
// err:
}
func ExampleExecAndStreamError() {
ExecAndStream("/", "man", []string{"Hello"})
// Output:
// cmd.Run() failed with exit status 16
//
// out:
//
// err:
// No manual entry for Hello
}
func TestExecAndGetLines(t *testing.T) { func TestExecAndGetLines(t *testing.T) {
testCommand := "echo" testCommand := "echo"
testArguments := []string{"$'Line1\nLine2\nLine3'"} testArguments := []string{"$'Line1\nLine2\nLine3'"}