Documentation ¶
Index ¶
- func Create(ctx context.Context, t *testing.T, apiClient client.APIClient, ...) string
- func CreateFromConfig(ctx context.Context, apiClient client.APIClient, config *TestContainerConfig) (container.CreateResponse, error)
- func GetContainerNS(ctx context.Context, t *testing.T, apiClient client.APIClient, ...) string
- func Inspect(ctx context.Context, t *testing.T, apiClient client.APIClient, ...) container.InspectResponse
- func IsInState(ctx context.Context, apiClient client.APIClient, containerID string, ...) func(log poll.LogT) poll.Result
- func IsRemoved(ctx context.Context, apiClient client.APIClient, containerID string) func(log poll.LogT) poll.Result
- func IsStopped(ctx context.Context, apiClient client.APIClient, containerID string) func(log poll.LogT) poll.Result
- func IsSuccessful(ctx context.Context, apiClient client.APIClient, containerID string) func(log poll.LogT) poll.Result
- func Remove(ctx context.Context, t *testing.T, apiClient client.APIClient, ...)
- func Run(ctx context.Context, t *testing.T, apiClient client.APIClient, ...) string
- func RunningStateFlagIs(ctx context.Context, apiClient client.APIClient, containerID string, ...) func(log poll.LogT) poll.Result
- func WithAdditionalGroups(groups ...string) func(c *TestContainerConfig)
- func WithAnnotations(annotations map[string]string) func(*TestContainerConfig)
- func WithAutoRemove(c *TestContainerConfig)
- func WithBind(src, target string) func(*TestContainerConfig)
- func WithBindRaw(s string) func(*TestContainerConfig)
- func WithCDIDevices(cdiDeviceNames ...string) func(*TestContainerConfig)
- func WithCapability(capabilities ...string) func(*TestContainerConfig)
- func WithCgroupnsMode(mode string) func(*TestContainerConfig)
- func WithCmd(cmds ...string) func(*TestContainerConfig)
- func WithConsoleSize(width, height uint) func(*TestContainerConfig)
- func WithContainerWideMacAddress(address string) func(c *TestContainerConfig)
- func WithDNS(dns []string) func(*TestContainerConfig)
- func WithDropCapability(capabilities ...string) func(*TestContainerConfig)
- func WithEndpointSettings(nw string, config *network.EndpointSettings) func(*TestContainerConfig)
- func WithExposedPorts(ports ...string) func(*TestContainerConfig)
- func WithExtraHost(extraHost string) func(*TestContainerConfig)
- func WithIPv4(networkName, ip string) func(*TestContainerConfig)
- func WithIPv6(networkName, ip string) func(*TestContainerConfig)
- func WithImage(image string) func(*TestContainerConfig)
- func WithIsolation(isolation container.Isolation) func(*TestContainerConfig)
- func WithLinks(links ...string) func(*TestContainerConfig)
- func WithLogDriver(driver string) func(*TestContainerConfig)
- func WithMacAddress(networkName, mac string) func(config *TestContainerConfig)
- func WithMount(m mount.Mount) func(*TestContainerConfig)
- func WithName(name string) func(*TestContainerConfig)
- func WithNetworkMode(mode string) func(*TestContainerConfig)
- func WithPIDMode(mode container.PidMode) func(c *TestContainerConfig)
- func WithPidsLimit(limit *int64) func(*TestContainerConfig)
- func WithPlatform(p *ocispec.Platform) func(*TestContainerConfig)
- func WithPortMap(pm nat.PortMap) func(*TestContainerConfig)
- func WithPrivileged(privileged bool) func(*TestContainerConfig)
- func WithRestartPolicy(policy container.RestartPolicyMode) func(c *TestContainerConfig)
- func WithRuntime(name string) func(*TestContainerConfig)
- func WithSecurityOpt(opt string) func(*TestContainerConfig)
- func WithStopSignal(stopSignal string) func(c *TestContainerConfig)
- func WithSysctls(sysctls map[string]string) func(*TestContainerConfig)
- func WithTmpfs(targetAndOpts string) func(config *TestContainerConfig)
- func WithTty(tty bool) func(*TestContainerConfig)
- func WithUser(user string) func(c *TestContainerConfig)
- func WithVolume(target string) func(*TestContainerConfig)
- func WithWindowsDevice(device string) func(*TestContainerConfig)
- func WithWorkingDir(dir string) func(*TestContainerConfig)
- type ContainerOutput
- type ExecResult
- type RunResult
- type TestContainerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
func Create(ctx context.Context, t *testing.T, apiClient client.APIClient, ops ...func(*TestContainerConfig)) string
Create creates a container with the specified options, asserting that there was no error.
func CreateFromConfig ¶
func CreateFromConfig(ctx context.Context, apiClient client.APIClient, config *TestContainerConfig) (container.CreateResponse, error)
CreateFromConfig creates a container from the given TestContainerConfig.
Example use:
ctr, err := container.CreateFromConfig(ctx, apiClient, container.NewTestConfig(container.WithAutoRemove)) assert.Check(t, err)
func GetContainerNS ¶
func GetContainerNS(ctx context.Context, t *testing.T, apiClient client.APIClient, cID, nsName string) string
GetContainerNS gets the value of the specified namespace of a container
func IsInState ¶
func IsInState(ctx context.Context, apiClient client.APIClient, containerID string, state ...string) func(log poll.LogT) poll.Result
IsInState verifies the container is in one of the specified state, e.g., "running", "exited", etc.
func IsRemoved ¶
func IsRemoved(ctx context.Context, apiClient client.APIClient, containerID string) func(log poll.LogT) poll.Result
IsRemoved verifies the container has been removed
func IsStopped ¶
func IsStopped(ctx context.Context, apiClient client.APIClient, containerID string) func(log poll.LogT) poll.Result
IsStopped verifies the container is in stopped state.
func IsSuccessful ¶
func IsSuccessful(ctx context.Context, apiClient client.APIClient, containerID string) func(log poll.LogT) poll.Result
IsSuccessful verifies state.Status == "exited" && state.ExitCode == 0
func Run ¶
func Run(ctx context.Context, t *testing.T, apiClient client.APIClient, ops ...func(*TestContainerConfig)) string
Run creates and start a container with the specified options
func RunningStateFlagIs ¶
func RunningStateFlagIs(ctx context.Context, apiClient client.APIClient, containerID string, running bool) func(log poll.LogT) poll.Result
RunningStateFlagIs polls for the container's Running state flag to be equal to running.
func WithAdditionalGroups ¶
func WithAdditionalGroups(groups ...string) func(c *TestContainerConfig)
WithAdditionalGroups sets the additional groups for the container
func WithAnnotations ¶
func WithAnnotations(annotations map[string]string) func(*TestContainerConfig)
WithAnnotations set the annotations for the container.
func WithAutoRemove ¶
func WithAutoRemove(c *TestContainerConfig)
WithAutoRemove sets the container to be removed on exit
func WithBind ¶
func WithBind(src, target string) func(*TestContainerConfig)
WithBind sets the bind mount of the container
func WithBindRaw ¶
func WithBindRaw(s string) func(*TestContainerConfig)
WithBindRaw sets the bind mount of the container
func WithCDIDevices ¶
func WithCDIDevices(cdiDeviceNames ...string) func(*TestContainerConfig)
WithCDIDevices sets the CDI devices to use to start the container
func WithCapability ¶
func WithCapability(capabilities ...string) func(*TestContainerConfig)
func WithCgroupnsMode ¶
func WithCgroupnsMode(mode string) func(*TestContainerConfig)
WithCgroupnsMode sets the cgroup namespace mode for the container
func WithCmd ¶
func WithCmd(cmds ...string) func(*TestContainerConfig)
WithCmd sets the comannds of the container
func WithConsoleSize ¶
func WithConsoleSize(width, height uint) func(*TestContainerConfig)
WithConsoleSize sets the initial console size of the container
func WithContainerWideMacAddress ¶
func WithContainerWideMacAddress(address string) func(c *TestContainerConfig)
func WithDNS ¶
func WithDNS(dns []string) func(*TestContainerConfig)
WithDNS sets external DNS servers for the container
func WithDropCapability ¶
func WithDropCapability(capabilities ...string) func(*TestContainerConfig)
func WithEndpointSettings ¶
func WithEndpointSettings(nw string, config *network.EndpointSettings) func(*TestContainerConfig)
func WithExposedPorts ¶
func WithExposedPorts(ports ...string) func(*TestContainerConfig)
WithExposedPorts sets the exposed ports of the container
func WithExtraHost ¶
func WithExtraHost(extraHost string) func(*TestContainerConfig)
WithExtraHost sets the user defined IP:Host mappings in the container's /etc/hosts file
func WithIPv4 ¶
func WithIPv4(networkName, ip string) func(*TestContainerConfig)
WithIPv4 sets the specified ip for the specified network of the container
func WithIPv6 ¶
func WithIPv6(networkName, ip string) func(*TestContainerConfig)
WithIPv6 sets the specified ip6 for the specified network of the container
func WithImage ¶
func WithImage(image string) func(*TestContainerConfig)
WithImage sets the image of the container
func WithIsolation ¶
func WithIsolation(isolation container.Isolation) func(*TestContainerConfig)
WithIsolation specifies the isolation technology to apply to the container
func WithLinks ¶
func WithLinks(links ...string) func(*TestContainerConfig)
WithLinks sets the links of the container
func WithLogDriver ¶
func WithLogDriver(driver string) func(*TestContainerConfig)
WithLogDriver sets the log driver to use for the container
func WithMacAddress ¶
func WithMacAddress(networkName, mac string) func(config *TestContainerConfig)
func WithName ¶
func WithName(name string) func(*TestContainerConfig)
WithName sets the name of the container
func WithNetworkMode ¶
func WithNetworkMode(mode string) func(*TestContainerConfig)
WithNetworkMode sets the network mode of the container
func WithPIDMode ¶
func WithPIDMode(mode container.PidMode) func(c *TestContainerConfig)
WithPIDMode sets the PID-mode for the container.
func WithPidsLimit ¶
func WithPidsLimit(limit *int64) func(*TestContainerConfig)
WithPidsLimit sets the container's "pids-limit
func WithPlatform ¶
func WithPlatform(p *ocispec.Platform) func(*TestContainerConfig)
WithPlatform specifies the desired platform the image should have.
func WithPortMap ¶
func WithPortMap(pm nat.PortMap) func(*TestContainerConfig)
WithPortMap sets/replaces port mappings.
func WithPrivileged ¶
func WithPrivileged(privileged bool) func(*TestContainerConfig)
WithPrivileged sets privileged mode for the container
func WithRestartPolicy ¶
func WithRestartPolicy(policy container.RestartPolicyMode) func(c *TestContainerConfig)
WithRestartPolicy sets container's restart policy
func WithRuntime ¶
func WithRuntime(name string) func(*TestContainerConfig)
WithRuntime sets the runtime to use to start the container
func WithSecurityOpt ¶
func WithSecurityOpt(opt string) func(*TestContainerConfig)
func WithStopSignal ¶
func WithStopSignal(stopSignal string) func(c *TestContainerConfig)
func WithSysctls ¶
func WithSysctls(sysctls map[string]string) func(*TestContainerConfig)
WithSysctls sets sysctl options for the container
func WithTmpfs ¶
func WithTmpfs(targetAndOpts string) func(config *TestContainerConfig)
WithTmpfs sets a target path in the container to a tmpfs, with optional options (separated with a colon).
func WithTty ¶
func WithTty(tty bool) func(*TestContainerConfig)
WithTty sets the TTY mode of the container
func WithVolume ¶
func WithVolume(target string) func(*TestContainerConfig)
WithVolume sets the volume of the container
func WithWindowsDevice ¶
func WithWindowsDevice(device string) func(*TestContainerConfig)
WithWindowsDevice specifies a Windows Device, ala `--device` on the CLI
func WithWorkingDir ¶
func WithWorkingDir(dir string) func(*TestContainerConfig)
WithWorkingDir sets the working dir of the container
Types ¶
type ContainerOutput ¶
type ContainerOutput struct {
Stdout, Stderr string
}
type ExecResult ¶
type ExecResult struct { ExitCode int // contains filtered or unexported fields }
ExecResult represents a result returned from Exec()
func Exec ¶
func Exec(ctx context.Context, apiClient client.APIClient, id string, cmd []string, ops ...func(*container.ExecOptions)) (ExecResult, error)
Exec executes a command inside a container, returning the result containing stdout, stderr, and exit code. Note:
- this is a synchronous operation;
- cmd stdin is closed.
func ExecT ¶
func ExecT(ctx context.Context, t testing.TB, apiClient client.APIClient, id string, cmd []string, ops ...func(*container.ExecOptions)) ExecResult
ExecT calls Exec() and aborts the test if an error occurs.
func (ExecResult) AssertSuccess ¶
func (res ExecResult) AssertSuccess(t testing.TB)
AssertSuccess fails the test and stops execution if the command exited with a nonzero status code.
func (ExecResult) Combined ¶
func (res ExecResult) Combined() string
Combined returns combined stdout and stderr output of a command run by Exec()
func (ExecResult) Stderr ¶
func (res ExecResult) Stderr() string
Stderr returns stderr output of a command run by Exec()
func (ExecResult) Stdout ¶
func (res ExecResult) Stdout() string
Stdout returns stdout output of a command run by Exec()
type TestContainerConfig ¶
type TestContainerConfig struct { Name string Config *container.Config HostConfig *container.HostConfig NetworkingConfig *network.NetworkingConfig Platform *ocispec.Platform }
TestContainerConfig holds container configuration struct that are used in api calls.
func NewTestConfig ¶
func NewTestConfig(ops ...func(*TestContainerConfig)) *TestContainerConfig
NewTestConfig creates a new TestContainerConfig with the provided options.
If no options are passed, it creates a default config, which is a busybox container running "top" (on Linux) or "sleep" (on Windows).