pgtest

package
v0.0.0-...-ea6506d Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package pgtest provides utilities for creating and destroying test databases in PostgreSQL. It's used in eventdb's Store and E2E tests. The code is based on and largely identical to chain's pgtest package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultURL is the default URL used for accessing the postgres server in open()
	DefaultURL = "postgres://localhost/postgres?sslmode=disable"

	// DefaultSchema is a SQL query that's executed when a new database is
	// created in NewDB. You can put SQL in here that you want to be executed
	// before every test.
	DefaultSchema = `
		-- this is slow, so only do it once per db
		CREATE EXTENSION IF NOT EXISTS postgis;
	`
)

Functions

func NewDB

func NewDB(t testing.TB) *sql.DB

NewDB creates a connection to a fresh PostgreSQL database for testing.

Don't worry about closing the DB. It will close on its own when garbage collected.

func NewTx

func NewTx(t testing.TB) *sql.Tx

NewTx creates a transaction in a fresh PostgreSQL database for testing. It's automatically rolled back when the Tx is garbage collected and potentially reused by another test.

Types

This section is empty.

Jump to

Keyboard shortcuts

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