Documentation
¶
Overview ¶
Package testdb owns AuthKit's Postgres integration-test harness.
Index ¶
- func ApplyMigrations(t testing.TB, ctx context.Context, dbURL string)
- func Pool(t testing.TB) *pgxpool.Pool
- func PoolWithTracer(t testing.TB, tracer pgx.QueryTracer) *pgxpool.Pool
- func ScratchRedis(t testing.TB) *redis.Client
- func URL(t testing.TB) string
- func UnlockedPool(t testing.TB) *pgxpool.Pool
- type Postgres
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyMigrations ¶
ApplyMigrations applies AuthKit's embedded Postgres migrations to dbURL.
func Pool ¶ added in v0.98.0
Pool connects to the shared, already-migrated integration database (URL) and holds the cross-package advisory lock for the test's lifetime; Cleanup releases both. Skips (or fails under AUTHKIT_TEST_REQUIRE_DB=1) without a URL.
func PoolWithTracer ¶ added in v0.98.0
PoolWithTracer is Pool with a pgx QueryTracer on every connection, for tests that count the queries a flow issues.
func ScratchRedis ¶ added in v0.98.0
ScratchRedis returns a client on a private logical database of the Redis named by AUTHKIT_TEST_REDIS_URL: one of the server's 16 DBs is leased with SET NX so concurrent test binaries never share a keyspace, and the DB is flushed on cleanup. Skips, or fails under AUTHKIT_TEST_REQUIRE_DB=1, when the URL is unset.
Types ¶
type Postgres ¶
Postgres is an isolated migrated database for integration tests.
func EmptyScratchPostgres ¶ added in v0.98.1
EmptyScratchPostgres is ScratchPostgres without the migrations, for tests that seed a ledger of their own before migrating.
func ScratchPostgres ¶
ScratchPostgres creates, migrates, and cleans up a scratch database on the server named by QUERY_TEST_DATABASE_URL, AUTHKIT_TEST_DATABASE_URL, or SQLC_DATABASE_URL. It skips (or fails under AUTHKIT_TEST_REQUIRE_DB=1) when no URL is provided so ordinary go test runs do not start integration infrastructure by accident.