Documentation
¶
Overview ¶
Package dbtest runs throwaway database servers in containers for the tests of the database extensions (SQL, MongoDB, Redis) that need a real server (build tag emetos_docker, CLAUDE.md "Testing notes"); it was extensions/sql/sqltest until step 20.1, which moved it here because an extension may not import another one. The containers are made through the harness of the container engine client (extensions/internal/containerapi/containerapitest), which keeps the rules of those tests:
- only the pinned images of containerapitest/images.go are pulled, never "latest";
- every container is named emetos-test-<random>, carries the label dev.emetos.test=1, publishes its port on 127.0.0.1 only and mounts nothing of the host;
- every container is removed when the test ends, also when it fails, and the harness fails the test when something labelled is left; scripts/container-test-cleanup.sh removes what a killed run left (it removes only what has the label);
- the user's own containers, images, networks and volumes are never listed, stopped, removed or changed;
- the password of a server is random for each test and goes to the engine in the body of the create call, so that it is in no command line and in no file.
There is no server for SQL Server: its image starts only when the license terms are accepted, and a test must not accept terms for the user. SQL Server's driver and dialect are tested against fakes.
The containers are started through the Runner interface: Docker and Podman run them on the user's engine, OnHarness on any harness (a fake engine in the tests of this package).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainerSpec ¶
func ContainerSpec(spec Spec) containerapi.ContainerSpec
ContainerSpec builds the container the harness makes for a spec. The harness adds the name, the label and the loopback address. It is separate so that the tests check what is asked without an engine: the environment in a stable order, the port as a container port only, no mount.
func RandomPassword ¶
RandomPassword returns a password for a server of one test: 20 random letters and digits and a suffix that satisfies the strictest rule of the servers (a password with upper and lower case letters, a digit and a symbol).
Types ¶
type Runner ¶
type Runner interface {
// Start runs the server and returns where it is published. It makes the test fail, or skips it, when it cannot.
Start(t testing.TB, spec Spec) Server
}
Runner starts a server for a test and removes it when the test ends.
func Docker ¶
func Docker() Runner
Docker returns the Runner on the user's Docker (as the Docker CLI would find it). It skips the test when no local engine answers.
func OnHarness ¶
func OnHarness(h *containerapitest.Harness) Runner
OnHarness returns the Runner on an existing harness, for example one on a fake engine.
type Server ¶
type Server struct {
// Name is the container's name.
Name string
// Host and Port are where the server's port is published: on the loopback address.
Host string
Port int
}
Server is a running container.
type Spec ¶
type Spec struct {
// Image is one of containerapitest.PinnedImages.
Image string
// Port is the port the server listens on inside the container.
Port int
// Env is the environment of the container.
Env map[string]string
// Args follow the image name (the arguments of the server).
Args []string
}
Spec is a server to run.