containertest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for a command to run in a container. If no timeout is given, this
	// is used. This will only affect the container running time, not the 'go test' timeout. If the timeout is
	// too long, the test will immediately fail with an error.
	DefaultTimeout = 45 * time.Minute
	// Do not set any explicit timeout.
	NoTimeout = 0

	// Default path to work directory in the test container.
	ContainerWorkDir = "/workdir"

	DefaultReaperTimeout = 10 * time.Minute
)

Variables

View Source
var (
	// ErrTimeout is returned when a scenario test exceeds the allowed time limit.
	ErrTimeout = errors.New("scenario test exceeded allowed time limit")
	// ErrUnsupported is returned when a scenario test is not supported on the current platform.
	ErrUnsupported = errors.New("not supported")
)

Functions

func RunCmdInContainer

func RunCmdInContainer(
	t *testing.T,
	collateral *ContainerCmdTestCollateral,
	cmd []string,
	timeout time.Duration,
) (results testhelpers.TestResults, err error)

RunCmdInContainer runs a command in a container. The command is run as the current user, and the working directory in the collateral object is mounted into the container at /workdir. The command is run from /workdir. The azldev command will be pre-provisioned in the container on available in the $PATH. If timeout is 0, the command will run until it exits or is killed by the go test timeout. If timeout is greater than 0, the command will be terminated at that time and the error 'ErrTimeout' will be returned.

Types

type ContainerCmdTestCollateral

type ContainerCmdTestCollateral struct {
	// contains filtered or unexported fields
}

Encapsulates the collateral for a containerized scenario test.

func NewContainerTestCollateral

func NewContainerTestCollateral(t *testing.T) *ContainerCmdTestCollateral

NewContainerTestCollateral constructs a new, default collateral object for a containerized test. Functions provided on the returned value allow updating its configuration.

func (*ContainerCmdTestCollateral) WithEnv

WithEnv sets the environment variables to be passed to the container.

func (*ContainerCmdTestCollateral) WithExtraFileContents

func (c *ContainerCmdTestCollateral) WithExtraFileContents(files map[string]io.Reader) *ContainerCmdTestCollateral

WithExtraFileContents adds extra files to the container. The files are created in the container with the string contents provided. The files are described with a map from the destination path in the container to a reader providing the contents to write.

func (*ContainerCmdTestCollateral) WithExtraFiles

WithExtraFiles adds extra files to the container. The files are copied from the host to the container, and described with a map from the destination path in the container to the source path on the host.

func (*ContainerCmdTestCollateral) WithExtraMounts

WithExtraMounts adds extra mounts to the container.

func (*ContainerCmdTestCollateral) WithNetwork

WithNetwork sets the container command to run with networking enabled.

func (*ContainerCmdTestCollateral) WithPrivilege

WithPrivilege sets the command to be run in a privileged container.

func (*ContainerCmdTestCollateral) WithTestBinaryPath

func (c *ContainerCmdTestCollateral) WithTestBinaryPath(path string) *ContainerCmdTestCollateral

WithTestBinaryPath points to the test binary that should be automatically added to the container's $PATH.

func (*ContainerCmdTestCollateral) Workdir

func (c *ContainerCmdTestCollateral) Workdir() string

Workdir returns the work directory for the test.

type ContainerMount

type ContainerMount struct {
	// contains filtered or unexported fields
}

func NewContainerMount

func NewContainerMount(source, destination string, flags []ContainerMountFlag) ContainerMount

NewContainerMount creates a new ContainerMount with the specified source and destination paths and optional flags. It will panic if the source or destination paths are empty, or if any of the provided flags are invalid. This is a test function with inputs predetermined at test development time, so panicking is acceptable for invalid usage.

func (*ContainerMount) ContainerMountString

func (cm *ContainerMount) ContainerMountString() string

type ContainerMountFlag

type ContainerMountFlag string
const (
	ContainerMountFlagReadOnly ContainerMountFlag = "ro"
	ContainerMountFlagZ        ContainerMountFlag = "z"
)

func (ContainerMountFlag) IsValid

func (f ContainerMountFlag) IsValid() error

Jump to

Keyboard shortcuts

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