Documentation
¶
Overview ¶
Package postgrestest provides a package intended for running tests which require a Postgres backend.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDisabled = errgo.New("postgres testing is disabled")
ErrDisabled is returned by New when postgres testing has been explicitly disabled.
Functions ¶
func PgTestDisable ¶ added in v1.1.1
func PgTestDisable() bool
PgTestDisable returns whether Postgres should be disabled based on the PGTESTDISABLE environment variable.
Types ¶
type DB ¶
DB holds a connection to a schema within a Postgres database. The schema is created by New and deleted (along with all the tables) when the DB is closed.
func New ¶
New connects to a Postgres instance and returns a database connection that uses a newly created schema with a random name. The PG* environment variables may be used to configure the connection parameters (see https://www.postgresql.org/docs/9.3/static/libpq-envars.html).
The returned DB instance must be closed after it's finished with.
If the environment variable PGTESTDISABLE is non-empty ErrDisabled will be returned.
If the environment variable PGTESTKEEPDB is non-empty, the name of the test schema will be printed and the data will not be deleted.
For optimal test performance, we recommend setting the following Postgres config values in your testing or development environment (BUT NEVER IN PRODUCTION):
fsync = off synchronous_commit = off full_page_writes = off
Be aware that these settings may lead to data loss and corruption. However, they should not have any negative impact on ephemeral tests.