None is a token to inform Result.Assert that the output should be empty
const None = "[NOTHING]"
Success is the default expected result. A Success result is one with a 0 ExitCode.
var Success = Expected{}
Cmd contains the arguments and options for a process to run as part of a test suite.
type Cmd struct { Command []string Timeout time.Duration Stdin io.Reader Stdout io.Writer Stderr io.Writer Dir string Env []string ExtraFiles []*os.File }
func Command(command string, args ...string) Cmd
Command create a simple Cmd with the specified command and arguments
CmdOp is an operation which modified a Cmd structure used to execute commands
type CmdOp func(*Cmd)
func Dir(path string) CmdOp
Dir sets the working directory of the command
func WithEnv(env ...string) CmdOp
WithEnv sets the environment variable of the command. Each arguments are in the form of KEY=VALUE
func WithExtraFile(f *os.File) CmdOp
WithExtraFile adds a file descriptor to the command
func WithStderr(w io.Writer) CmdOp
WithStderr sets the standard error of the command to the specified writer
func WithStdin(r io.Reader) CmdOp
WithStdin sets the standard input of the command to the specified reader
func WithStdout(w io.Writer) CmdOp
WithStdout sets the standard output of the command to the specified writer
func WithTimeout(timeout time.Duration) CmdOp
WithTimeout sets the timeout duration of the command
Expected is the expected output from a Command. This struct is compared to a Result struct by Result.Assert().
type Expected struct { ExitCode int Timeout bool Error string Out string Err string }
Result stores the result of running a command
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 }
func RunCmd(cmd Cmd, cmdOperators ...CmdOp) *Result
RunCmd runs a command and returns a Result
▹ Example
func RunCommand(command string, args ...string) *Result
RunCommand runs a command with default options, and returns a result
▹ Example
func StartCmd(cmd Cmd, cmdOperators ...CmdOp) *Result
StartCmd starts a command, but doesn't wait for it to finish
func WaitOnCmd(timeout time.Duration, result *Result) *Result
WaitOnCmd waits for a command to complete. If timeout is non-nil then only wait until the timeout.
func (r *Result) Assert(t assert.TestingT, exp Expected) *Result
Assert compares the Result against the Expected struct, and fails the test if any of the expectations are not met.
This function is equivalent to assert.Assert(t, result.Equal(exp)).
func (r *Result) Combined() string
Combined returns the stdout and stderr combined into a single string
func (r *Result) Compare(exp Expected) error
Compare the result to Expected and return an error if they do not match.
func (r *Result) Equal(exp Expected) cmp.Comparison
Equal compares the result to Expected. If the result doesn't match expected returns a formatted failure message with the command, stdout, stderr, exit code, and any failed expectations.
func (r *Result) Stderr() string
Stderr returns the stderr of the process as a string
func (r *Result) Stdout() string
Stdout returns the stdout of the process as a string
func (r *Result) String() string
Name | Synopsis |
---|---|
.. |