dbtest

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 RandomName

func RandomName(t testing.TB) string

RandomName returns emetos-test-<random>.

func RandomPassword

func RandomPassword(t testing.TB) string

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.

func Podman

func Podman() Runner

Podman returns the Runner on the user's Podman. It skips the test when there is no Podman.

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.

Jump to

Keyboard shortcuts

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