Documentation
¶
Overview ¶
Package dbtest gives one test its own Postgres schema.
It lives outside kit/db so that kit/db exports no DDL door: an application connection can only reach the database through db.Run or db.RunSystem, and the owner connection a test needs for CREATE TABLE is a plain *sql.DB opened here. Nothing in kit/ imports this package; only tests do.
The schema travels in the connection URL, as options=-csearch_path=<schema>, so every connection a pool opens from it lands in the same place, and so does everything db.Migrate creates: the ledger and the tenancy helper functions are private to the test rather than shared through public.
Index ¶
- func Open(t *testing.T, rawURL string) *sql.DB
- func OpenFor(t testing.TB, rawURL string) *sql.DB
- func RoleOf(t *testing.T, rawURL string) string
- func Schema(t *testing.T, extra ...db.MigrationSource) (admin *sql.DB, app *db.Conn)
- func System(ctx context.Context, conn *db.Conn, ...) error
- func SystemToken() tenancy.SystemToken
- func URLs(t *testing.T) (adminURL, appURL string)
- func URLsFor(t testing.TB) (adminURL, appURL string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenFor ¶ added in v1.1.0
OpenFor is Open for tests and benchmarks, with the same automatic cleanup.
func RoleOf ¶
RoleOf is the login role of a connection URL, so a test names the same role the app connects as instead of hard-coding it a second time.
func Schema ¶
Schema creates an isolated database schema with the kernel's tables and the named capabilities — a module's exported Migrations source, such as task.Migrations, and the sources of the modules it depends on (auth needs user). It returns an owner handle for assertions and an application connection subject to row-level security. A test that names no capability gets the tenancy, outbox and limits tables and nothing else.
func System ¶
func System(ctx context.Context, conn *db.Conn, fn func(context.Context, db.Tx[db.System]) error) error
System runs fn in a cross-tenant transaction, for a test that has to reach the tables no tenant owns: the tenant registry, and the outbox as the relay sees it.
func SystemToken ¶
func SystemToken() tenancy.SystemToken
SystemToken is that capability, for a test of something the application hands one to: a module's control-plane routes take api.SystemToken(), and a job that has to cross tenants takes it in Module.Routes, so a test of either has to be able to stand where the kernel stands.
func URLs ¶
URLs creates the schema and returns the two connection URLs that reach it: the first owns it and holds the DDL rights, the second is the unprivileged role row-level security binds. The schema is dropped when the test ends.
It fails rather than skips when the environment names no database. A suite that quietly skips the isolation tests proves nothing.
Types ¶
This section is empty.