Documentation ¶
Index ¶
- func GetConfig(t testing.TB, database string) config.DB
- func SetHealthyNodes(t testing.TB, ctx context.Context, db glsql.Querier, ...)
- func SetMigrations(t testing.TB, db DB, cfg config.Config, up int)
- func WaitForBlockedQuery(ctx context.Context, t testing.TB, db glsql.Querier, queryPrefix string)
- type DB
- type TxWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfig ¶ added in v14.7.0
GetConfig returns the database configuration determined by environment variables. See NewDB() for the list of variables.
func SetHealthyNodes ¶
func SetHealthyNodes(t testing.TB, ctx context.Context, db glsql.Querier, healthyNodes map[string]map[string][]string)
SetHealthyNodes sets the healthy nodes in the database as determined by the passed in map. The healthyNodes map is keyed by praefect name -> virtual storage -> storage. On each run, it clears all previous health checks from the table, so the passed in nodes are the only ones considered healthy after the function. As the healthy nodes are determined by the time of the last successful health check, this should be run in the same transastion as the tested query to prevent flakiness.
func SetMigrations ¶ added in v14.8.0
SetMigrations ensures the requested number of migrations are up and the remainder are down.
func WaitForBlockedQuery ¶ added in v14.7.0
WaitForBlockedQuery is a helper that waits until a blocked query matching the prefix is present in the database. This is useful for ensuring another transaction is blocking a query when testing concurrent execution of multiple queries.
Types ¶
type DB ¶ added in v14.7.0
DB is a helper struct that should be used only for testing purposes.
func New ¶ added in v14.7.0
New returns a wrapper around the database connection pool. Must be used only for testing. The new database with empty relations will be created for each call of this function. It uses env vars:
PGHOST - required, URL/socket/dir PGPORT - required, binding port PGUSER - optional, user - `$ whoami` would be used if not provided
Once the test is completed the database will be dropped on test cleanup execution.
func (DB) Begin ¶ added in v14.7.0
Begin starts a new transaction and returns it wrapped into TxWrapper.
func (DB) Close ¶ added in v14.7.0
Close removes schema if it was used and releases connection pool.
func (DB) MustExec ¶ added in v14.7.0
MustExec executes `q` with `args` and verifies there are no errors.
func (DB) RequireRowsInTable ¶ added in v14.7.0
RequireRowsInTable verifies that `tname` table has `n` amount of rows in it.
func (DB) Truncate ¶ added in v14.7.0
Truncate removes all data from the list of tables and restarts identities for them.
func (DB) TruncateAll ¶ added in v14.7.0
TruncateAll removes all data from known set of tables.
type TxWrapper ¶ added in v14.7.0
TxWrapper is a simple wrapper around *sql.Tx.