Documentation
¶
Overview ¶
Package testsupport holds helpers shared by tests across packages. Nothing in the running binary imports it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DropSchemas ¶
func DropSchemas(names ...string)
DropSchemas removes schemas created by this run. Call it from TestMain after m.Run(), so a unique-per-run name does not turn a collision problem into unbounded schema sprawl in a shared database.
Failures are reported rather than fatal: leaving a schema behind is untidy, but failing the suite over cleanup would turn a healthy run red.
func MustSkipWithoutDB ¶
MustSkipWithoutDB skips loudly when no test database is configured.
`go test` prints nothing for a skipped test without -v, so a suite that silently skips its only DB-backed coverage looks exactly like one that passed.
func OpenSchema ¶
OpenSchema returns a database handle whose search_path is a schema private to this test binary invocation, and migrates models into it.
It exists so that no test package has to assemble this itself. Every part of it is a step that was, at some point, omitted somewhere in this tree: opening the DSN unscoped writes into public, which against a developer's own DATABASE_URL means the suite migrates and truncates real tables; and a schema name shared between runs means two invocations tread on each other's fixtures. A helper is the only version of this that stays correct as test files are added.
Pass a schema from SchemaName, held in a package-level var, so that TestMain can hand the same name to DropSchemas afterwards.
func OpenSchemaWithParams ¶
func OpenSchemaWithParams(t *testing.T, schema string, params map[string]string, models ...any) *gorm.DB
OpenSchemaWithParams is OpenSchema with extra DSN query parameters — a session TimeZone, say, for a suite asserting that date arithmetic is done in UTC rather than in whatever zone the server happens to run in.
func SchemaName ¶
SchemaName returns a schema name unique to this test binary invocation.
Postgres identifiers truncate at 63 bytes, so a long base would silently collide again after truncation — hence the explicit cap rather than trusting callers to keep names short.
Types ¶
This section is empty.