Documentation
¶
Overview ¶
Package testdb gives tests one shared Postgres and one shared MariaDB server per machine, and isolated databases on them.
`go test ./...` runs every package in its own process, so process-global state can't keep packages from starting their own containers. Instead:
- In CI (EP_CI=1) the servers are the workflow's service containers (EP_TEST_POSTGRES_HOST/PORT, EP_TEST_MYSQL_HOST/PORT).
- Locally each server is a testcontainers container with a fixed name and Reuse enabled. Finding or starting it happens under an OS file lock, so concurrent test processes agree on one container instead of racing. The containers keep running between `go test` runs (their data lives in RAM, without fsync); remove them with `docker rm -f etherpad-test-postgres-v2 etherpad-test-mysql-v2`.
- Tests never share a database: each caller gets its own (NewDatabase), so packages can run in parallel against the same servers.
Set EP_TEST_SKIP_SQL_SERVERS=1 to skip everything that needs a server.
Index ¶
Constants ¶
const ( // User and password of both servers (CI services and containers). User = "test_user" Password = "test_password" )
Variables ¶
This section is empty.
Functions ¶
func PgBouncer ¶ added in v0.7.0
func PgBouncer() bool
PgBouncer reports that the PostgreSQL server is reached through PgBouncer in transaction mode (EP_TEST_POSTGRES_PGBOUNCER=1): the data stores then avoid named prepared statements, like with dbSettings.pgBouncer.
func SkipIfDisabled ¶ added in v0.7.0
SkipIfDisabled skips the test when servers of this kind are switched off: EP_TEST_SKIP_SQL_SERVERS for all, EP_TEST_SKIP_MYSQL for MySQL (CI's PgBouncer job only has PostgreSQL).
func SkipSQLServers ¶
func SkipSQLServers() bool
SkipSQLServers reports whether tests needing Postgres/MySQL should be skipped.
Types ¶
type Server ¶
Server is a running database server tests can create databases on.
func Acquire ¶
Acquire returns the shared server of the given kind, starting or attaching to it on first use in this process.
func Get ¶
Get is Acquire for tests: it skips the test when EP_TEST_SKIP_SQL_SERVERS is set and fails it when the server is unavailable.
func (*Server) AdminUser ¶
AdminUser is the account tests should connect as: it owns the databases created by NewDatabase.
func (*Server) CreateDatabase ¶
CreateDatabase creates a new empty database and returns its name. The caller is responsible for dropping it (see NewDatabase for tests).
func (*Server) DriverName ¶
DriverName is the database/sql driver for this server.
func (*Server) DropDatabase ¶
DropDatabase drops a database created by CreateDatabase.