Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents exclusive access to a database.
func (*DB) Connect ¶
Connect establishes a single connection to db. If the test only needs a single connection and does not have any transactional behavior of its own then prefer TxConnect as it may be faster. A t.Cleanup function is registered to close the connection at the end of the test so no explicit cleanup is required.
func (*DB) PoolConnect ¶
PoolConnect establishes a connection pool to db. A t.Cleanup function is registered to release the pool at the end of the test so no explicit cleanup is required.
func (*DB) TxConnect ¶
TxConnect establishes a single connection to db and starts a transaction. With pgundolog the transaction is unnecesary but tests may run faster when run in a transaction due to writes not needing to actually be durable until commit (which never will happen). A t.Cleanup function is registered to close the connection at the end of the test so no explicit cleanup is required.
type Manager ¶
type Manager struct { // AfterAcquireDB is called after a DB is acquired. It can be used to do setup such as loading fixtures or canaries. // t.Cleanup can be used to register cleanup or final tests such as checking canary health. conn is the maintenance // connection to db. AfterAcquireDB func(t testing.TB, db *DB, conn *pgx.Conn) // MakeConnConfig is used by DBs created by this Manager to configure connections. It returns a *pgx.ConnConfig for // suitable for connecting to connConfig.Database. connConfig is what would have been used if MakeConnConfig was nil. // connConfig may be modified and returned or an entirely new *pgx.ConnConfig may be created. // // connConfig is a copy of the *pgx.ConnConfig used to establish the manager connection, but with the Database field // replaced with the actual database to be connected to and with a OnNotice handler that logs PostgreSQL notices to MakeConnConfig func(t testing.TB, connConfig *pgx.ConnConfig) *pgx.ConnConfig // AfterConnect is called by DB.Connect after a connection is established. It is also used by any pool returned from // DB.ConnectPool. If an error is returned the connection will be closed. AfterConnect func(ctx context.Context, conn *pgx.Conn) error // ResetDB is called to reset a database to pristine condition. ResetDB func(ctx context.Context, conn *pgx.Conn) error // contains filtered or unexported fields }
Manager manages access to test databases. Connect or ConnectConfig must be called before any other methods.
func (*Manager) AcquireDB ¶
AcquireDB acquires a DB for exclusive use. A t.Cleanup function is registered to release the database at the end of the test so no explicit cleanup is required.