The Testing Infrastructure provides the mechanisms to validate Docker Engine functionality across multiple layers, from individual Go packages to full API and CLI workflows. It encompasses specialized test runners, a dedicated daemon management framework for integration testing, and a suite of helpers to simulate complex container operations.
The Docker testing framework is categorized into four primary levels of validation:
integration/ directory.docker binary to verify CLI behavior. Located in integration-cli/.docker-py.The following diagram illustrates how tests are initiated and the infrastructure that supports their execution.
Sources: integration-cli/check_test.go54-103 integration/container/create_test.go10-30 integration/internal/container/ops.go16-18 internal/testutil/daemon/daemon.go1-50
The modern integration suite (found in integration/) focuses on testing the Engine API directly using the official Go client.
The testutil/daemon package provides the Daemon struct, which encapsulates a background dockerd process. This allows tests to spin up isolated Engine instances with specific configurations (e.g., custom storage drivers, experimental features, or user namespaces).
Key functions in testutil/daemon:
daemon.New(t): Initializes a new daemon instance for a test integration/daemon/daemon_test.go39d.Start(t, args...): Launches the daemon process with provided CLI flags integration/daemon/daemon_test.go42d.Stop(t): Gracefully shuts down the daemon and cleans up resources integration/daemon/daemon_test.go40d.Restart(t, args...): Restarts the daemon, often used to test state persistence integration/container/daemon_linux_test.go115Tests utilize a set of internal packages to simplify container and network manipulation:
integration/internal/container provides functional options (ConfigOpt) to build container configurations integration/internal/container/ops.go17-18poll package (from gotest.tools) is used with helpers like container.IsInState to wait for asynchronous operations to complete integration/container/kill_test.go28 integration/container/stop_test.go15A typical integration test follows this lifecycle:
setupTest(t) to initialize the environment integration/container/create_test.go33container.Run or container.Create with options like WithImage, WithCmd, or WithRestartPolicy integration/container/stop_test.go28-32apiClient (e.g., ContainerKill, ContainerStop) integration/container/kill_test.go78-80Sources: integration/container/create_test.go32-71 integration/container/stop_test.go22-47 integration/internal/container/ops.go1-100 internal/testutil/daemon/daemon.go1-100
Integration-CLI tests (legacy) focus on the docker binary. They use a suite-based approach where tests are grouped into classes like DockerCLIRunSuite or DockerDaemonSuite.
OSType, IsRootless status, and API versions integration/container/run_linux_test.go35-40The following diagram bridges natural language test requirements to the specific code entities used in the CLI and API integration layers.
Sources: integration/container/stop_test.go40 integration/container/kill_test.go23 integration/container/daemon_linux_test.go115 integration/internal/container/ops.go17-50
The daemon/graphdriver/graphtest package provides a standardized test suite for storage drivers (e.g., overlay2, btrfs). This ensures that any graph driver implementation adheres to the required interface behaviors.
GetDriver creates or retrieves a driver instance for testing daemon/graphdriver/graphtest/graphtest_unix.go62DriverTestCreateEmpty: Verifies new layers are empty daemon/graphdriver/graphtest/graphtest_unix.go84DriverTestDeepLayerRead: Tests performance and correctness across many filesystem layers daemon/graphdriver/graphtest/graphtest_unix.go144DriverTestDiffApply: Validates the export/import (diff) logic between layers daemon/graphdriver/graphtest/graphtest_unix.go174Sources: daemon/graphdriver/graphtest/graphtest_unix.go27-174
Testing requires strict control over host resources to prevent interference between tests.
skip.If to bypass platform-specific or requirement-specific tests (e.g., skipping Windows-only tests on Linux) integration/container/run_linux_test.go35 integration/container/create_test.go147t.Cleanup() and helper functions like container.Remove to ensure the daemon state is reset integration/container/create_test.go138 integration/container/mounts_linux_test.go52RootDir is often set to a temporary directory to isolate filesystem changes integration/daemon/daemon_test.go49Sources: integration/container/create_test.go147 integration/container/run_linux_test.go35-40 integration/daemon/daemon_test.go49-53 integration/container/mounts_linux_test.go52-57
Refresh this wiki