testutil

package
v2.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Nerdctl = Target("nerdctl")
	Docker  = Target("docker")
)
View Source
const (
	FedoraESGZImage = "ghcr.io/stargz-containers/fedora:30-esgz"            // eStargz
	FfmpegSociImage = "public.ecr.aws/soci-workshop-examples/ffmpeg:latest" // SOCI
	UbuntuImage     = "public.ecr.aws/docker/library/ubuntu:23.10"          // Large enough for testing soci index creation
)
View Source
const Namespace = "nerdctl-test"

Variables

View Source
var (
	BusyboxImage                = "ghcr.io/containerd/busybox:1.28"
	AlpineImage                 = mirrorOf("alpine:3.13")
	NginxAlpineImage            = mirrorOf("nginx:1.19-alpine")
	NginxAlpineIndexHTMLSnippet = "<title>Welcome to nginx!</title>"
	RegistryImage               = mirrorOf("registry:2")
	WordpressImage              = mirrorOf("wordpress:5.7")
	WordpressIndexHTMLSnippet   = "<title>WordPress &rsaquo; Installation</title>"
	MariaDBImage                = mirrorOf("mariadb:10.5")
	DockerAuthImage             = mirrorOf("cesanta/docker_auth:1.7")
	FluentdImage                = mirrorOf("fluent/fluentd:v1.14-1")
	KuboImage                   = mirrorOf("ipfs/kubo:v0.16.0")
	SystemdImage                = "ghcr.io/containerd/stargz-snapshotter:0.15.1-kind"

	// Source: https://gist.github.com/cpuguy83/fcf3041e5d8fb1bb5c340915aabeebe0
	NonDistBlobImage = "ghcr.io/cpuguy83/non-dist-blob:latest"
	// Foreign layer digest
	NonDistBlobDigest = "sha256:be691b1535726014cdf3b715ff39361b19e121ca34498a9ceea61ad776b9c215"

	CommonImage = AlpineImage

	// This error string is expected when attempting to connect to a TCP socket
	// for a service which actively refuses the connection.
	// (e.g. attempting to connect using http to an https endpoint).
	// It should be "connection refused" as per the TCP RFC.
	// https://www.rfc-editor.org/rfc/rfc793
	ExpectedConnectionRefusedError = "connection refused"
)

Functions

func DockerIncompatible

func DockerIncompatible(t testing.TB)

func GetDaemonIsKillable

func GetDaemonIsKillable() bool

func GetEnableIPv6

func GetEnableIPv6() bool

func GetTarget

func GetTarget() string

func Identifier

func Identifier(t testing.TB) string

Identifier can be used as a name of container, image, volume, network, etc.

func ImageRepo

func ImageRepo(s string) string

ImageRepo returns the image repo that can be used to, e.g, validate output from `nerdctl images`.

func M

func M(m *testing.M)

func NewDelayOnceReader

func NewDelayOnceReader(wrapped io.Reader) io.Reader

NewDelayOnceReader returns a wrapper around io.Reader that delays the first Read() by one second. It is used to test detaching from a container, and the reason why we need this is described below:

Since detachableStdin.closer cancels the corresponding container's IO, it has to be invoked after the corresponding task is started, or the container could be resulted in an invalid state.

However, in taskutil.go, the goroutines that copy the container's IO start right after container.NewTask(ctx, ioCreator) is invoked and before the function returns, which means that detachableStdin.closer could be invoked before the task is started, and that's indeed the case for e2e test as the detach keys are "entered immediately".

Since detaching from a container is only applicable when there is a TTY, which usually means that there's a human in front of the computer waiting for a prompt to start typing, it's reasonable to assume that the user will not type the detach keys before the task is started.

Besides delaying the first Read() by one second, the returned reader also sleeps for one second if EOF is reached for the wrapped reader. The reason follows:

NewDelayOnceReader is usually used with `unbuffer -p`, which has a caveat: "unbuffer simply exits when it encounters an EOF from either its input or process2." [1] The implication is if we use `unbuffer -p` to feed a command to container shell, `unbuffer -p` will exit right after it finishes reading the command (i.e., encounter an EOF from its input), and by that time, the container may have not executed the command and printed the wanted results to stdout, which would fail the test if it asserts stdout to contain certain strings.

As a result, to avoid flaky tests, we give the container shell one second to process the command before `unbuffer -p` exits.

[1] https://linux.die.net/man/1/unbuffer

func RequireContainerdPlugin

func RequireContainerdPlugin(base *Base, requiredType, requiredID string, requiredCaps []string)

func RequireDaemonVersion

func RequireDaemonVersion(b *Base, constraint string)

func RequireExecPlatform

func RequireExecPlatform(t testing.TB, ss ...string)

func RequireExecutable

func RequireExecutable(t testing.TB, name string)

RequireExecutable skips tests when executable `name` is not present in PATH.

func RequireKernelVersion

func RequireKernelVersion(t testing.TB, constraint string)

func RequireSystemService

func RequireSystemService(t testing.TB, sv string)

func RequiresBuild

func RequiresBuild(t testing.TB)

func WithStdin

func WithStdin(r io.Reader) func(*Cmd)

WithStdin sets the standard input of Cmd to the specified reader

Types

type Base

type Base struct {
	T                testing.TB
	Target           Target
	DaemonIsKillable bool
	EnableIPv6       bool
	IPv6Compatible   bool
	Binary           string
	Args             []string
	Env              []string
}

func NewBase

func NewBase(t *testing.T) *Base

func NewBaseWithIPv6Compatible

func NewBaseWithIPv6Compatible(t *testing.T) *Base

func NewBaseWithNamespace

func NewBaseWithNamespace(t *testing.T, ns string) *Base

func (*Base) Cmd

func (b *Base) Cmd(args ...string) *Cmd

func (*Base) CmdWithHelper

func (b *Base) CmdWithHelper(helper []string, args ...string) *Cmd

func (*Base) ComposeCmd

func (b *Base) ComposeCmd(args ...string) *Cmd

ComposeCmd executes `nerdctl -n nerdctl-test compose` or `docker-compose`

func (*Base) ComposeCmdWithHelper

func (b *Base) ComposeCmdWithHelper(helper []string, args ...string) *Cmd

func (*Base) ContainerdAddress

func (b *Base) ContainerdAddress() string

func (*Base) DumpDaemonLogs

func (b *Base) DumpDaemonLogs(minutes int)

func (*Base) EnsureContainerExited

func (b *Base) EnsureContainerExited(con string, expectedExitCode int)

func (*Base) EnsureContainerStarted

func (b *Base) EnsureContainerStarted(con string)

func (*Base) EnsureDaemonActive

func (b *Base) EnsureDaemonActive()

func (*Base) Info

func (b *Base) Info() dockercompat.Info

func (*Base) InfoNative

func (b *Base) InfoNative() native.Info

func (*Base) InspectContainer

func (b *Base) InspectContainer(name string) dockercompat.Container

func (*Base) InspectImage

func (b *Base) InspectImage(name string) dockercompat.Image

func (*Base) InspectNetwork

func (b *Base) InspectNetwork(name string) dockercompat.Network

func (*Base) InspectVolume

func (b *Base) InspectVolume(name string, args ...string) native.Volume

func (*Base) KillDaemon

func (b *Base) KillDaemon()

type Cmd

type Cmd struct {
	icmd.Cmd
	*Base
}

func (*Cmd) Assert

func (c *Cmd) Assert(expected icmd.Expected)

func (*Cmd) AssertCombinedOutContains

func (c *Cmd) AssertCombinedOutContains(s string)

func (*Cmd) AssertErrContains

func (c *Cmd) AssertErrContains(s string)

func (*Cmd) AssertErrNotContains

func (c *Cmd) AssertErrNotContains(s string)

func (*Cmd) AssertExitCode

func (c *Cmd) AssertExitCode(exitCode int)

func (*Cmd) AssertFail

func (c *Cmd) AssertFail()

func (*Cmd) AssertNoOut

func (c *Cmd) AssertNoOut(s string)

func (*Cmd) AssertOK

func (c *Cmd) AssertOK()

func (*Cmd) AssertOutContains

func (c *Cmd) AssertOutContains(s string)

func (*Cmd) AssertOutContainsAll

func (c *Cmd) AssertOutContainsAll(strs ...string)

AssertOutContainsAll checks if command output contains All strings in `strs`.

func (*Cmd) AssertOutContainsAny

func (c *Cmd) AssertOutContainsAny(strs ...string)

AssertOutContainsAny checks if command output contains Any string in `strs`.

func (*Cmd) AssertOutExactly

func (c *Cmd) AssertOutExactly(s string)

func (*Cmd) AssertOutNotContains

func (c *Cmd) AssertOutNotContains(s string)

func (*Cmd) AssertOutStreamsExactly

func (c *Cmd) AssertOutStreamsExactly(stdout, stderr string)

func (*Cmd) AssertOutStreamsWithFunc

func (c *Cmd) AssertOutStreamsWithFunc(fn func(stdout, stderr string) error)

func (*Cmd) AssertOutWithFunc

func (c *Cmd) AssertOutWithFunc(fn func(stdout string) error)

func (*Cmd) CmdOption

func (c *Cmd) CmdOption(cmdOptions ...func(*Cmd)) *Cmd

func (*Cmd) Out

func (c *Cmd) Out() string

func (*Cmd) OutLines

func (c *Cmd) OutLines() []string

func (*Cmd) Run

func (c *Cmd) Run() *icmd.Result

type ComposeDir

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

func NewComposeDir

func NewComposeDir(t testing.TB, dockerComposeYAML string) *ComposeDir

func (*ComposeDir) CleanUp

func (cd *ComposeDir) CleanUp()

func (*ComposeDir) Dir

func (cd *ComposeDir) Dir() string

func (*ComposeDir) ProjectName

func (cd *ComposeDir) ProjectName() string

func (*ComposeDir) WriteFile

func (cd *ComposeDir) WriteFile(name, content string)

func (*ComposeDir) YAMLFullPath

func (cd *ComposeDir) YAMLFullPath() string

type Target

type Target = string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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