containertest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package containertest gates the tests that start containers (decision 0015) and starts the blob-store emulators they use.

Role

Test support, outside the modules, for every package whose tests need Docker. They need a Docker daemon that runs Linux containers: GitHub's Windows runners have a healthy Docker that runs only Windows containers, so testcontainers' own health check passes and every Linux image then fails to start. Those tests skip there and run on Linux and on macOS with Docker Desktop.

Inputs

  • The Docker engine that testcontainers finds, asked once per test binary, within AnswerTimeout, whether it runs Linux containers.
  • The -short flag: a short run skips every container test.

Outputs

  • RequireLinux, which skips a test, and CheckLinux, which returns an error, when no usable engine answers.
  • MinIO, FakeGCS and Azurite, and RunMinIO, RunFakeGCS and RunAzurite for callers without a testing.T: one emulator container per caller, from an image pinned by digest, removed when the caller ends. MinIO is handed out only once it serves S3 requests, not merely HTTP. Each image is pulled before its module starts, one pull per image at a time in the process. A pull that fails moves on to the image's second source, a registry serving the same digest (for Azurite, the project's copy on GHCR, which .github/workflows/emulator-copy.yml makes), and when every source fails the error names each registry's answer rather than the "No such image" testcontainers' own pull ends in.

References

Status

Implemented P2 (the Linux engine gate), P2b (the emulators) and P7 (the answer timeout). MinIO's readiness wait added by issue 1307; the checked image pull and the second sources by issue 1448; Azurite's copy by issue 1463.

Index

Constants

View Source
const (
	// MinIOImage is Chainguard's build of MinIO: MinIO stopped publishing
	// minio/minio on Docker Hub and its quay.io images need credentials.
	// This digest carries RELEASE.2026-09-22T19-25-18Z of
	// github.com/chainguard-forks/minio (`minio --version`), the release
	// RunMinIO's readiness wait was checked against; recheck that wait on a
	// bump.
	MinIOImage = "cgr.dev/chainguard/minio@" + minioDigest
	// FakeGCSImage is fake-gcs-server 1.56.1.
	FakeGCSImage = "fsouza/fake-gcs-server:1.56.1@" + fakeGCSDigest
	// AzuriteImage is Azurite 3.37.0, the first release with Put Block From
	// URL. Its baseline API version is older than the one the Azure SDK
	// sends, so it runs with --skipApiVersionCheck (research 18).
	AzuriteImage = "mcr.microsoft.com/azure-storage/azurite@" + azuriteDigest
)
View Source
const AnswerTimeout = 5 * time.Second

AnswerTimeout is how long the Docker engine has to answer before the tests that need it skip. A working engine answers in milliseconds, a CI runner's included. Docker Desktop on macOS can accept connections on its socket and then never answer (#458); testcontainers' own calls take no deadline there, so without this bound every Docker-backed test blocked until the package's -timeout killed the binary and hid every other result in it.

Variables

This section is empty.

Functions

func CheckLinux

func CheckLinux(ctx context.Context) error

CheckLinux returns an error unless a Docker daemon that runs Linux containers answers within AnswerTimeout, for callers without a *testing.T. The first call's answer holds for the rest of the test binary: an engine that did not answer once is not waited on again by every later test, and one that did is not asked again.

func FakeGCS

func FakeGCS(t *testing.T) string

FakeGCS starts fake-gcs-server for t and returns its JSON API endpoint, ending in "/storage/v1/" as the Cloud Storage client's option.WithEndpoint needs. It skips t where Docker cannot run Linux containers.

func RequireLinux

func RequireLinux(t *testing.T)

RequireLinux skips t unless a Docker daemon that runs Linux containers answers and the run is not -short.

func RunFakeGCS

func RunFakeGCS(ctx context.Context) (string, func(), error)

RunFakeGCS starts fake-gcs-server and returns its JSON API endpoint, as FakeGCS does, and a function that removes it, for callers without a *testing.T such as acceptance steps; check CheckLinux first.

Types

type AzuriteEndpoint

type AzuriteEndpoint struct {
	// ServiceURL is the account URL with a trailing slash. Its host is an IP
	// address: the Azure SDK treats a non-IP host as virtual-hosted style,
	// and Azurite is path style.
	ServiceURL string
	Account    string
	Key        string
}

AzuriteEndpoint addresses Azurite's blob service.

func Azurite

func Azurite(t *testing.T) AzuriteEndpoint

Azurite starts Azurite's blob service for t, or skips t where Docker cannot run Linux containers.

func RunAzurite

func RunAzurite(ctx context.Context) (AzuriteEndpoint, func(), error)

RunAzurite starts Azurite's blob service and returns its endpoint and a function that removes it, for callers without a *testing.T such as acceptance steps; check CheckLinux first.

type MinIOEndpoint

type MinIOEndpoint struct {
	// URL is the S3 endpoint, for example "http://127.0.0.1:32768"; MinIO
	// needs path-style addressing.
	URL      string
	User     string
	Password string
}

MinIOEndpoint addresses a MinIO server.

func MinIO

func MinIO(t *testing.T) MinIOEndpoint

MinIO starts MinIO for t, or skips t where Docker cannot run Linux containers.

func RunMinIO

func RunMinIO(ctx context.Context) (MinIOEndpoint, func(), error)

RunMinIO starts MinIO and returns its endpoint and a function that removes it, for callers without a *testing.T such as acceptance steps; check CheckLinux first. It returns once MinIO serves S3 requests.

Jump to

Keyboard shortcuts

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