github.com/reconquest/executil-go@v0.0.0-20181110204642-1f5c2d67813f/utils_test.go (about)

     1  package executil
     2  
     3  import "os/exec"
     4  
     5  var commandsWithError = []struct {
     6  	get         func() *exec.Cmd
     7  	isExitError bool
     8  }{
     9  	{getCommandWithUnknownBinary, false},
    10  	{getCommandWithStdoutAndStderrAndExitStatus1, true},
    11  	{getCommandWithStdoutAndStderrAndExitStatus2, true},
    12  }
    13  
    14  func getCommandWithStdoutAndStderr() *exec.Cmd {
    15  	return exec.Command(
    16  		"bash", "-c", "echo stdout; sleep 0.05;  echo stderr >&2",
    17  	)
    18  }
    19  
    20  func getCommandWithStdout() *exec.Cmd {
    21  	return exec.Command(
    22  		"bash", "-c", "echo stdout;",
    23  	)
    24  }
    25  
    26  func getCommandWithStderr() *exec.Cmd {
    27  	return exec.Command(
    28  		"bash", "-c", "echo stderr >&2",
    29  	)
    30  }
    31  
    32  func getCommandWithStdoutAndStderrAndExitStatus1() *exec.Cmd {
    33  	return exec.Command(
    34  		"bash", "-c", "echo stdout; sleep 0.05; echo stderr >&2; exit 1",
    35  	)
    36  }
    37  
    38  func getCommandWithStdoutAndStderrAndExitStatus2() *exec.Cmd {
    39  	return exec.Command(
    40  		"bash", "-c", "echo stdout; sleep 0.05; echo stderr >&2; exit 2",
    41  	)
    42  }
    43  
    44  func getCommandWithUnknownBinary() *exec.Cmd {
    45  	return exec.Command(
    46  		"___i_am_realy_does_not_exist_on_the_system", "--flag",
    47  	)
    48  }