dbtest

package
v0.0.0-...-b475dd9 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package dbtest provides utilities to use dockertest with PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunWithDB

func RunWithDB(t *testing.T, name string, f func(*TDB))

RunWithDB creates a new database for a subtest.

func WithDB

func WithDB(t *testing.T, f func(*TDB))

WithDB is like RunWithDB except it doesn't start a new sub-test.

func TestFunction(t *testing.T) {
    dbtest.WithDB(t, func(t) {
        // do stuff here
    })
}

func WithPool

func WithPool(f func() int, opts ...DBConfigFn) int

WithPool makes sure we have a valid database pool. You should wrap your TestMain invocation with this.

func TestMain(m *testing.M) {
    os.Exit(withPool(m.Run))
}

Types

type DBConfigFn

type DBConfigFn func(c *dbCfg)

func WithImage

func WithImage(img string) DBConfigFn

func WithInit

func WithInit(b []byte) DBConfigFn

type TDB

type TDB struct {
	*testing.T
	DB *sql.DB
}

Jump to

Keyboard shortcuts

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