testutil

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 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"

	NginxAlpineIndexHTMLSnippet = "<title>Welcome to nginx!</title>"
	WordpressIndexHTMLSnippet   = "<title>WordPress &rsaquo; Installation</title>"

	// Source: https://gist.github.com/cpuguy83/fcf3041e5d8fb1bb5c340915aabeebe0
	NonDistBlobImage = "ghcr.io/cpuguy83/non-dist-blob:latest@sha256:8859ffb0bb604463fe19f1e606ceda9f4f8f42e095bf78c42458cf6da7b5c7e7"
	// Foreign layer digest
	NonDistBlobDigest = "sha256:be691b1535726014cdf3b715ff39361b19e121ca34498a9ceea61ad776b9c215"
)
View Source
const Namespace = "nerdctl-test"

Variables

View Source
var (
	AlpineImage         = GetTestImage("alpine")
	BusyboxImage        = GetTestImage("busybox")
	DockerAuthImage     = GetTestImage("docker_auth")
	FluentdImage        = GetTestImage("fluentd")
	GolangImage         = GetTestImage("golang")
	KuboImage           = GetTestImage("kubo")
	MariaDBImage        = GetTestImage("mariadb")
	NginxAlpineImage    = GetTestImage("nginx")
	RegistryImageStable = GetTestImage("registry")
	SystemdImage        = GetTestImage("stargz")
	WordpressImage      = GetTestImage("wordpress")

	CommonImage = AlpineImage

	FedoraESGZImage = GetTestImage("fedora_esgz") // eStargz
	FfmpegSociImage = GetTestImage("ffmpeg_soci") // SOCI
	UbuntuImage     = GetTestImage("ubuntu")      // Large enough for testing soci index creation
)

Functions

func DockerIncompatible

func DockerIncompatible(t testing.TB)

func GetAllowModifyUsers added in v2.1.0

func GetAllowModifyUsers() bool

func GetDaemonIsKillable

func GetDaemonIsKillable() bool

func GetEnableIPv6

func GetEnableIPv6() bool

func GetEnableKubernetes

func GetEnableKubernetes() bool

func GetFlakyEnvironment

func GetFlakyEnvironment() bool

func GetTarget

func GetTarget() string

func GetTestImage added in v2.1.4

func GetTestImage(key string) string

func GetTestImageConfigDigest added in v2.1.4

func GetTestImageConfigDigest(key, platform string) string

func GetTestImageDigest added in v2.1.4

func GetTestImageDigest(key string) string

func GetTestImageManifestDigest added in v2.1.4

func GetTestImageManifestDigest(key, platform string) string

func GetTestImageMediaType added in v2.1.4

func GetTestImageMediaType(key string) string

func GetTestImagePlatformMediaType added in v2.1.4

func GetTestImagePlatformMediaType(key, platform string) string

func GetTestImageRaw added in v2.1.4

func GetTestImageRaw(key, platform string) string

func GetTestImageSchemaVersion added in v2.1.4

func GetTestImageSchemaVersion(key string) int

func GetTestImageWithoutTag added in v2.1.4

func GetTestImageWithoutTag(key string) string

func Identifier

func Identifier(t testing.TB) string

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

func IsDocker

func IsDocker() bool

func LoadProject

func LoadProject(fileName, projectName string, envMap map[string]string) (*compose.Project, error)

Load is used only for unit testing.

func M

func M(m *testing.M)

func RegisterBuildCacheCleanup

func RegisterBuildCacheCleanup(t *testing.T)

RegisterBuildCacheCleanup adds a 'builder prune --all --force' cleanup function to run on test teardown.

func RequireContainerdPlugin

func RequireContainerdPlugin(base *Base, requiredType, requiredID string, requiredCaps []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               string
	DaemonIsKillable     bool
	EnableIPv6           bool
	IPv6Compatible       bool
	EnableKubernetes     bool
	KubernetesCompatible bool
	Binary               string
	Args                 []string
	Env                  []string
	Dir                  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
	// contains filtered or unexported fields
}

func (*Cmd) Assert

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

func (*Cmd) AssertCombinedOutContains

func (c *Cmd) AssertCombinedOutContains(s string)

func (*Cmd) AssertExitCode

func (c *Cmd) AssertExitCode(exitCode int)

func (*Cmd) AssertFail

func (c *Cmd) AssertFail()

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

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

func (*Cmd) Start

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

type ComposeDir

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

func NewComposeDir

func NewComposeDir(t tig.T, 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 TestImage added in v2.1.3

type TestImage struct {
	Ref           string                  `yaml:"ref"`
	Tag           string                  `yaml:"tag,omitempty"`
	SchemaVersion int                     `yaml:"schemaversion,omitempty"`
	MediaType     string                  `yaml:"mediatype,omitempty"`
	Digest        string                  `yaml:"digest,omitempty"`
	Variants      []string                `yaml:"variants,omitempty"`
	Manifests     map[string]manifestInfo `yaml:"manifests,omitempty"`
}

Directories

Path Synopsis
portlock provides a mechanism for containers to acquire and release ports they plan to expose, and a wait mechanism This allows tests dependent on running containers to always parallelize without having to worry about port collision with any other test Note that this does NOT protect against trying to use a port that is already used by an unrelated third-party service or container Also note that *generally* finding a free port is not easy: - to just "listen" and see if it works won't work for containerized services that are DNAT-ed (plus, that would be racy) - inspecting iptables instead (or in addition to) may work for containers, but this depends on how networking has been set (and yes, it is also racy) Our approach here is optimistic: tests are responsible for calling Acquire and Release
portlock provides a mechanism for containers to acquire and release ports they plan to expose, and a wait mechanism This allows tests dependent on running containers to always parallelize without having to worry about port collision with any other test Note that this does NOT protect against trying to use a port that is already used by an unrelated third-party service or container Also note that *generally* finding a free port is not easy: - to just "listen" and see if it works won't work for containerized services that are DNAT-ed (plus, that would be racy) - inspecting iptables instead (or in addition to) may work for containers, but this depends on how networking has been set (and yes, it is also racy) Our approach here is optimistic: tests are responsible for calling Acquire and Release

Jump to

Keyboard shortcuts

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