dbtest

package
v0.0.0-...-9f124b0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package dbtest is a package to ease the pain of developing test code that works against external databases. It provides helper functions to provision temporary databases and load them with test data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	Dialect string
	DSN     string
	// contains filtered or unexported fields
}

DB represents an ephemeral database that can be starts blank and can be used to run tests against.

func Mysql

func Mysql(t *testing.T) *DB

Mysql provisions a new, blank database with a random name on the localhost of the running process. It assumes that you have mysql running and that the root user has access with no password. It panics on the event of a failure.

func Postgres

func Postgres(t *testing.T) *DB

Postgres provisions a new, blank database with a random name on the localhost of the running process. It assumes that you have postgres running on the default port, have the command line postgres tools installed, and that the current user has access to the server. It panics on the event of a failure.

func Sqlite

func Sqlite(t *testing.T) *DB

Sqlite provisions a new, blank database sqlite database. It panics on the event of a failure.

func (*DB) Close

func (db *DB) Close()

Close closes and deletes the database represented by `db`

func (*DB) Load

func (db *DB) Load(sql string) *DB

Load executes all of the statements in the provided sql script against the test database, panicking if any fail. The receiver is returned allowing for chain-style calling within your test functions.

func (*DB) Open

func (db *DB) Open() *sqlx.DB

Open opens a sqlx connection to the db.

Jump to

Keyboard shortcuts

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