Documentation
¶
Overview ¶
Package pgtest gives a test its own Postgres database, migrated to the store's current Postgres schema, with connections as the roles the hosted build runs as. Tests run on Postgres when MAILRULES_TEST_POSTGRES_DSN names a superuser connection, and on SQLite otherwise.
The schema is migrated once into a template database named after a hash of the migration files, so a changed migration gets a new template; each test's database is a copy of it, dropped when the test ends. The package must not import the store: the store's own tests use it.
Index ¶
Constants ¶
const ( AsApp = appRole AsWorker = workerRole AsOwner = ownerRole )
Roles a test can sign in to its database as, by URL.
const EnvDSN = "MAILRULES_TEST_POSTGRES_DSN"
EnvDSN names the environment variable holding the superuser DSN.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DB ¶
type DB struct {
// App is connected as mailrules_test_app, a member of mailrules_app: what the store runs on.
App *sql.DB
// Worker is connected as mailrules_test_worker, a member of mailrules_worker.
Worker *sql.DB
// Admin is connected as the DSN's superuser, which row-level security does not apply
// to. Its queries may use SQLite's ? and ?N placeholders: they are rewritten to $n
// (outside quotes and comments), so tests' raw SQL written for SQLite runs unchanged.
Admin *sql.DB
// Name is the database's name.
Name string
}
DB is one test's own database, made from a template migrated to the current Postgres set.