Documentation
¶
Overview ¶
Package testdb connects integration tests to PostgreSQL.
Tests that need a database call Pool. They are skipped when the TASKMILL_TEST_DATABASE_URL environment variable is unset; `make test` sets it to the database that `make db` starts. Each test gets its own schema, so tests can run in parallel and leave nothing behind.
To run the tests through a transaction-pooling proxy such as PgBouncer, point TASKMILL_TEST_DATABASE_URL at the proxy and TASKMILL_TEST_LISTEN_URL at the database itself: workers then listen for notifications on a direct connection, which the proxy cannot provide.
Index ¶
- Constants
- func CheckGroups(tb testing.TB, pool *pgxpool.Pool, schema string)
- func DirectURL(tb testing.TB) string
- func ListenConfig(tb testing.TB) *pgx.ConnConfig
- func Pool(tb testing.TB) *pgxpool.Pool
- func PoolSize(tb testing.TB, conns int32) *pgxpool.Pool
- func Schema(tb testing.TB, pool *pgxpool.Pool) string
- func URL(tb testing.TB) string
Constants ¶
const ( EnvURL = "TASKMILL_TEST_DATABASE_URL" // the test database URL EnvListenURL = "TASKMILL_TEST_LISTEN_URL" // a direct URL, if EnvURL goes through a proxy )
Environment variables that configure the test database.
Variables ¶
This section is empty.
Functions ¶
func CheckGroups ¶ added in v0.2.0
CheckGroups fails the test unless every FIFO group of schema satisfies the invariants in docs/design/task-lifecycle.md: its count matches its unfinished tasks plus a halting dead head, it has exactly one head, and every unfinished grouped task belongs to a group row.
func DirectURL ¶ added in v0.2.0
DirectURL returns a URL that reaches the test database without a proxy: EnvListenURL if it is set, or else EnvURL. Tests that set connection parameters, which proxies refuse, connect with it.
func ListenConfig ¶ added in v0.2.0
func ListenConfig(tb testing.TB) *pgx.ConnConfig
ListenConfig returns the connection that workers listen on: EnvListenURL's, or nil if it is unset, which makes workers listen on their pools'.
func Pool ¶
Pool returns a pool of up to 8 connections to the test database, closed when the test ends.
func PoolSize ¶
PoolSize is Pool with a given number of connections, for tests that run many operations at once.
Types ¶
This section is empty.