Documentation
¶
Overview ¶
Package icmd executes binaries and provides convenient assertions for testing the results.
Index ¶
Examples ¶
Constants ¶
const ( // None is a token to inform Result.Assert that the output should be empty None string = "<NOTHING>" )
Variables ¶
var Success = Expected{}
Success is the default expected result. A Success result is one with a 0 ExitCode.
Functions ¶
func GetExitCode ¶
GetExitCode returns the ExitStatus of a process from the error returned by exec.Run(). If the exit status could not be parsed an error is returned.
Types ¶
type Cmd ¶
type Cmd struct {
Command []string
Timeout time.Duration
Stdin io.Reader
Stdout io.Writer
Dir string
Env []string
}
Cmd contains the arguments and options for a process to run as part of a test suite.
type Expected ¶
Expected is the expected output from a Command. This struct is compared to a Result struct by Result.Assert().
type Result ¶
type Result struct {
Cmd *exec.Cmd
ExitCode int
Error error
// Timeout is true if the command was killed because it ran for too long
Timeout bool
// contains filtered or unexported fields
}
Result stores the result of running a command
func RunCmd ¶
RunCmd runs a command and returns a Result
Example ¶
result := RunCmd(Command("cat /does/not/exist"))
result.Assert(t, Expected{
ExitCode: 1,
Err: "cat: /does/not/exist: No such file or directory",
})
func RunCommand ¶
RunCommand parses a command line and runs it, returning a result
Example ¶
result := RunCommand("bash", "-c", "echo all good")
result.Assert(t, Success)
func WaitOnCmd ¶
WaitOnCmd waits for a command to complete. If timeout is non-nil then only wait until the timeout.
func (*Result) Assert ¶
Assert compares the Result against the Expected struct, and fails the test if any of the expectations are not met.
func (*Result) Compare ¶
Compare returns a formatted error with the command, stdout, stderr, exit code, and any failed expectations nolint: gocyclo
func (*Result) SetExitError ¶
SetExitError sets Error and ExitCode based on Error