test

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureDBReady added in v2.0.1

func EnsureDBReady(ctx context.Context) (error, func())

EnsureDBReady is a helper utility that can be inserted into a test during development to make it simpler to run the test in isolation. Docker will be called to start a db that is read to be used with GetDatabase. Example usage:

dberr, cleanup := dbtest.EnsureDBReady(ctx)
require.NoError(t, dberr)
defer cleanup()

_, db := dbtest.GetDatabase(t)
defer db.Close()

While the code is somewhat robust to having existing dbs running, this is not intended to be left in the test code. The goal is that you can run individual tests via your IDE integrations or using the CLI, e.g.

go test -run ^TestRetentionHandler$`

func EqualCount

func EqualCount(t *testing.T, db *sql.DB, expected int, table string, filter squirrel.Sqlizer, msgAndArgs ...interface{}) int

EqualCount asserts that the count of rows matches the expected value given the table and WHERE query and args.EqualCount Note that this is a simple COUNT of rows in a single table. More complex queries should be constructed by hand.

func GetDatabase

func GetDatabase(t *testing.T, inits ...DBInitializer) (name string, testDB *sql.DB)

GetDatabase gets a test database

Types

type DBInitializer

type DBInitializer func(context.Context, *sql.DB) error

DBInitializer is the function that initializes the data base for testing

Jump to

Keyboard shortcuts

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