Documentation ¶
Index ¶
- func GetConfig(tb testing.TB, database string) config.DB
- func SetHealthyNodes(tb testing.TB, ctx context.Context, db glsql.Querier, ...)
- func SetMigrations(tb testing.TB, db DB, cfg config.Config, up int)
- func WaitForBlockedQuery(tb testing.TB, ctx context.Context, db glsql.Querier, queryPrefix string)
- type DB
- func (db DB) Begin(tb testing.TB) *TxWrapper
- func (db DB) Close() error
- func (db DB) MustExec(tb testing.TB, q string, args ...interface{})
- func (db DB) RequireRowsInTable(tb testing.TB, tname string, n int)
- func (db DB) Truncate(tb testing.TB, tables ...string)
- func (db DB) TruncateAll(tb testing.TB)
- type TxWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfig ¶
GetConfig returns the database configuration determined by environment variables. See NewDB() for the list of variables.
func SetHealthyNodes ¶
func SetHealthyNodes(tb 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 ¶
SetMigrations ensures the requested number of migrations are up and the remainder are down.
func WaitForBlockedQuery ¶
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 ¶
DB is a helper struct that should be used only for testing purposes.
func New ¶
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) RequireRowsInTable ¶
RequireRowsInTable verifies that `tname` table has `n` amount of rows in it.
func (DB) Truncate ¶
Truncate removes all data from the list of tables and restarts identities for them.
func (DB) TruncateAll ¶
TruncateAll removes all data from known set of tables.