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 ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 is URLs with migrations/ applied and both handles open: the owner as a plain *sql.DB, because DDL is all a test wants it for, and the application role as a *db.Conn, because db.Open is the only way to obtain one and it refuses any role row-level security would not bind.
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.