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 ¶
var MySQLEngines = []Engine{MySQL, MariaDB}
MySQLEngines are the engines that speak the MySQL dialect.
Functions ¶
func Each ¶
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 OpenMySQL ¶ added in v1.2.5
OpenMySQL opens a second pool on engine's container — MySQL or MariaDB — with exactly the DSN parameters given, for tests of what the CMS does with a DSN that lacks some of mysqlParams. The schema is the shared pool's, already migrated. The pool closes when the test ends.
func RequiredMySQLParams ¶ added in v1.2.5
func RequiredMySQLParams() []string
RequiredMySQLParams returns a copy of the DSN parameters every MySQL pool the CMS uses must carry, for a test to drop one of.
func SkipWithoutDocker ¶ added in v0.9.5
SkipWithoutDocker skips the calling test when there is no usable Docker daemon, so the unit-test suite still runs on machines without one.