Documentation
¶
Index ¶
- Constants
- Variables
- func RunCmdInContainer(t *testing.T, collateral *ContainerCmdTestCollateral, cmd []string, ...) (results testhelpers.TestResults, err error)
- type ContainerCmdTestCollateral
- func (c *ContainerCmdTestCollateral) WithEnv(env map[string]string) *ContainerCmdTestCollateral
- func (c *ContainerCmdTestCollateral) WithExtraFileContents(files map[string]io.Reader) *ContainerCmdTestCollateral
- func (c *ContainerCmdTestCollateral) WithExtraFiles(files map[string]string) *ContainerCmdTestCollateral
- func (c *ContainerCmdTestCollateral) WithExtraMounts(mounts []ContainerMount) *ContainerCmdTestCollateral
- func (c *ContainerCmdTestCollateral) WithNetwork() *ContainerCmdTestCollateral
- func (c *ContainerCmdTestCollateral) WithPrivilege() *ContainerCmdTestCollateral
- func (c *ContainerCmdTestCollateral) WithTestBinaryPath(path string) *ContainerCmdTestCollateral
- func (c *ContainerCmdTestCollateral) Workdir() string
- type ContainerMount
- type ContainerMountFlag
Constants ¶
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 ¶
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 ¶
func (c *ContainerCmdTestCollateral) WithEnv(env map[string]string) *ContainerCmdTestCollateral
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 ¶
func (c *ContainerCmdTestCollateral) WithExtraFiles(files map[string]string) *ContainerCmdTestCollateral
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 ¶
func (c *ContainerCmdTestCollateral) WithExtraMounts(mounts []ContainerMount) *ContainerCmdTestCollateral
WithExtraMounts adds extra mounts to the container.
func (*ContainerCmdTestCollateral) WithNetwork ¶
func (c *ContainerCmdTestCollateral) WithNetwork() *ContainerCmdTestCollateral
WithNetwork sets the container command to run with networking enabled.
func (*ContainerCmdTestCollateral) WithPrivilege ¶
func (c *ContainerCmdTestCollateral) WithPrivilege() *ContainerCmdTestCollateral
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