tcli

package
v1.28.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

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

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.

func (*Assertable) Assert

func (a *Assertable) Assert(t *testing.T, option ...Assertion)

Assert runs the Assertable and.

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

func DurationGreaterThan(dur time.Duration) Assertion

DurationGreaterThan asserts that the command completed in greater than the given duration.

func DurationLessThan

func DurationLessThan(dur time.Duration) Assertion

DurationLessThan asserts that the command completed in less than the given duration.

func Error

func Error() Assertion

Error asserts that the command exited with a nonzero exit code.

func ExitCodeIs

func ExitCodeIs(code int) Assertion

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

func StderrMatches(pattern string) Assertion

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

func StdoutMatches(pattern string) Assertion

StdoutMatches asserts that Stdout contains a substring which matches the given regexp.

func Success

func Success() Assertion

Success asserts that the command exited with an exit code of 0.

type CommandResult

type CommandResult struct {
	Stdout, Stderr []byte
	ExitCode       int
	Duration       time.Duration
}

CommandResult contains the aggregated result of a command execution.

type ContainerConfig

type ContainerConfig struct {
	Name       string
	Image      string
	BindMounts map[string]string
}

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) Close

func (r *HostRunner) Close() error

Close is a noop for HostRunner.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL