postgrestest

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2019 License: LGPL-3.0 Imports: 7 Imported by: 0

README

Simple support for Go testing with a live Postgres database
----

This package makes it straightforward to write tests that connect
to a fresh Postgres database created for the tests.

Documentation

Overview

Package postgrestest provides a package intended for running tests which require a Postgres backend.

Index

Constants

This section is empty.

Variables

View Source
var ErrDisabled = errgo.New("postgres testing is disabled")

ErrDisabled is returned by New when postgres testing has been explicitly disabled.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

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

func New() (*DB, error)

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.

func (*DB) Close

func (pg *DB) Close() error

Close closes the database connection and removes the test database.

func (*DB) Schema

func (pg *DB) Schema() string

Schema returns the test schema name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL