Documentation ¶
Overview ¶
Package tcli provides a framework for CLI integration testing. Execute commands on the raw host or inside a docker container. Define custom Assertion types to extend test functionality.
Index ¶
- type Assertable
- type Assertion
- func DurationGreaterThan(dur time.Duration) Assertion
- func DurationLessThan(dur time.Duration) Assertion
- func Error() Assertion
- func ExitCodeIs(code int) Assertion
- func GetResult(result **CommandResult) Assertion
- func StderrEmpty() Assertion
- func StderrJSONUnmarshal(target interface{}) Assertion
- func StderrMatches(pattern string) Assertion
- func StdoutEmpty() Assertion
- func StdoutJSONUnmarshal(target interface{}) Assertion
- func StdoutMatches(pattern string) Assertion
- func Success() Assertion
- type CommandResult
- type ContainerConfig
- type ContainerRunner
- type HostRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assertable ¶
type Assertable struct {
// contains filtered or unexported fields
}
Assertable describes an initialized command ready to be run and asserted against.
type Assertion ¶
type Assertion func(t *testing.T, r *CommandResult)
Assertion specifies an assertion on the given CommandResult. Pass custom Assertion functions to cover special cases.
func DurationGreaterThan ¶
DurationGreaterThan asserts that the command completed in greater than the given duration.
func DurationLessThan ¶
DurationLessThan asserts that the command completed in less than the given duration.
func ExitCodeIs ¶
ExitCodeIs asserts that the command exited with the given code.
func GetResult ¶
func GetResult(result **CommandResult) Assertion
GetResult offers an escape hatch from tcli The pointer passed as "result" will be assigned to the command's *CommandResult.
func StderrEmpty ¶
func StderrEmpty() Assertion
StderrEmpty asserts that the command did not write any data to Stderr.
func StderrJSONUnmarshal ¶
func StderrJSONUnmarshal(target interface{}) Assertion
StderrJSONUnmarshal attempts to unmarshal stderr into the given target.
func StderrMatches ¶
StderrMatches asserts that Stderr contains a substring which matches the given regexp.
func StdoutEmpty ¶
func StdoutEmpty() Assertion
StdoutEmpty asserts that the command did not write any data to Stdout.
func StdoutJSONUnmarshal ¶
func StdoutJSONUnmarshal(target interface{}) Assertion
StdoutJSONUnmarshal attempts to unmarshal stdout into the given target.
func StdoutMatches ¶
StdoutMatches asserts that Stdout contains a substring which matches the given regexp.
type CommandResult ¶
CommandResult contains the aggregated result of a command execution.
type ContainerConfig ¶
ContainerConfig describes the ContainerRunner configuration schema for initializing a testing environment.
type ContainerRunner ¶
type ContainerRunner struct {
// contains filtered or unexported fields
}
ContainerRunner specifies a runtime container for performing command tests.
func NewContainerRunner ¶
func NewContainerRunner(ctx context.Context, config *ContainerConfig) (*ContainerRunner, error)
NewContainerRunner starts a new docker container for executing command tests.
func (*ContainerRunner) Close ¶
func (r *ContainerRunner) Close() error
Close kills and removes the command execution testing container.
func (*ContainerRunner) Run ¶
func (r *ContainerRunner) Run(ctx context.Context, command string) *Assertable
Run executes the given command in the runtime container with reasonable defaults. "command" is executed in a shell as an argument to "sh -c".
func (*ContainerRunner) RunCmd ¶
func (r *ContainerRunner) RunCmd(cmd *exec.Cmd) *Assertable
RunCmd lifts the given *exec.Cmd into the runtime container.
type HostRunner ¶
type HostRunner struct{}
HostRunner executes command tests on the host, outside of a container.
func (*HostRunner) Run ¶
func (r *HostRunner) Run(ctx context.Context, command string) *Assertable
Run executes the given command on the host. "command" is executed in a shell as an argument to "sh -c".
func (*HostRunner) RunCmd ¶
func (r *HostRunner) RunCmd(cmd *exec.Cmd) *Assertable
RunCmd executes the given *exec.Cmd on the host.