Help us shape the future of Go! Take the 2026 Go Developer Survey

dockertest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package dockertest holds helpers for Docker integration tests. Every helper works through the Engine API of the daemon under test, so the tests run the same against any daemon DOCKER_HOST names.

Index

Constants

View Source
const (
	RegistryUsername = "testuser"
	RegistryPassword = "testpassword"
)

Generic credentials the authenticated test registry accepts.

View Source
const HelperStderrMarker = "synthetic-helper-stderr-marker"

HelperStderrMarker is what the fake credential helper writes to its stderr on every call, so that tests can check it never surfaces.

View Source
const RegistryImage = "registry:2"

RegistryImage is the registry the tests run.

Variables

This section is empty.

Functions

func DockerConfig

func DockerConfig(t testing.TB, cfg string) string

DockerConfig writes a Docker client configuration directory whose config.json holds cfg, and returns it. It clears DOCKER_AUTH_CONFIG so that only the written file applies.

func EnsureImage

func EnsureImage(t testing.TB, ctx context.Context, cli *dockerclient.Client, ref string)

EnsureImage pulls ref when the daemon does not have it. It never removes an image.

func RemoveImage

func RemoveImage(t testing.TB, ctx context.Context, cli *dockerclient.Client, ref string)

RemoveImage removes a test-owned image reference. Callers must only pass references created by their test; shared base images must never be removed.

func StartRegistry

func StartRegistry(t testing.TB, ctx context.Context, cli *dockerclient.Client) string

StartRegistry runs a test-owned registry container on the daemon and returns its address as the daemon reaches it ("127.0.0.1:<port>", which the daemon treats as an insecure registry). The container is removed when the test ends.

Types

type AuthRegistry

type AuthRegistry struct {
	// Addr is the registry as the daemon reaches it, "127.0.0.1:<port>".
	// The daemon treats it as an insecure registry, so it accepts the
	// certificate.
	Addr string
	// Client is an HTTP client that trusts the registry certificate.
	Client *http.Client
}

AuthRegistry is a test-owned registry that serves TLS with a self-signed certificate and requires Basic credentials.

func StartAuthRegistry

func StartAuthRegistry(t testing.TB, ctx context.Context, cli *dockerclient.Client) *AuthRegistry

StartAuthRegistry runs an AuthRegistry container on the daemon. The container is removed when the test ends.

func (*AuthRegistry) HelperConfig

func (r *AuthRegistry) HelperConfig(t testing.TB, name string) (dir, log string)

HelperConfig puts a fake docker-credential-<name> on PATH that answers "get" for the registry with its credentials, and writes a Docker client configuration whose credHelpers name it for the registry. It returns the configuration directory and the file the helper appends each requested server URL to.

func (*AuthRegistry) PushArtifact

func (r *AuthRegistry) PushArtifact(t testing.TB, repo, tag, configType string, config []byte, layerType string, layers ...[]byte)

PushArtifact uploads blobs and the manifest that references them to repo:tag with the registry's credentials. config is the manifest's config blob; layers are its layer blobs with the given media type.

func (*AuthRegistry) StaticAuthConfig

func (r *AuthRegistry) StaticAuthConfig(t testing.TB) string

StaticAuthConfig writes a Docker client configuration with a static auths entry for the registry, and returns its directory.

Jump to

Keyboard shortcuts

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