dbtest

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package dbtest runs the CMS's store tests against real database engines in throwaway containers.

The suite exists because the CMS speaks SQL to more than one engine: a test that passes on Postgres proves nothing about MySQL. Each registers a subtest per engine, so a single test body becomes the conformance check for every engine the CMS claims to support.

Tests written against this harness should drive stores through their public API rather than raw SQL. A test that reaches for SQL directly has to be written once per dialect, which is exactly the duplication the harness is meant to remove.

Containers are started lazily, once per engine per test process, and shared by every test in the package. Between tests, Truncate empties the cms_ tables — far cheaper than a fresh database per test. When Docker is not available the whole suite skips rather than fails, so `go test ./...` still passes on a machine without it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each

func Each(t *testing.T, fn func(t *testing.T, db *sqldb.DB))

Each runs fn as a subtest against every engine under test, handing it a migrated, empty database. Use it as the entry point for any test that touches storage:

func TestPageInsert(t *testing.T) {
    dbtest.Each(t, func(t *testing.T, db *sqldb.DB) {
        store := content.NewStore(db, "en")
        ...
    })
}

func SkipWithoutDocker added in v0.9.5

func SkipWithoutDocker(t *testing.T)

SkipWithoutDocker skips the calling test when there is no usable Docker daemon, so the unit-test suite still runs on machines without one.

func Truncate

func Truncate(t *testing.T, db *sqldb.DB)

Truncate empties every cms_ table, leaving the schema in place. The table list is read from the database rather than hardcoded, so a new migration needs no change here.

Types

type Engine

type Engine string

Engine names one database engine under test.

const (
	Postgres Engine = "postgres"
	MySQL    Engine = "mysql"
	MariaDB  Engine = "mariadb"
)

Jump to

Keyboard shortcuts

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