integration

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Overview

Package integration is a helper for running integration tests.

Index

Constants

View Source
const (
	// EnvPGConnString is the environment variable examined for a DSN for a
	// pre-existing database engine. If unset, an appropriate database will
	// attempt to be downloaded and run.
	EnvPGConnString = "POSTGRES_CONNECTION_STRING"

	// EnvPGVersion is the environment variable examined for the version of
	// PostgreSQL used if an embedded binary would be used.
	EnvPGVersion = `PGVERSION`
)

Variables

This section is empty.

Functions

func DBSetup added in v0.5.0

func DBSetup() func()

DBSetup queues setup and teardown for a postgres engine instance. If the "integration" build tag is not provided, then nothing is done. If the environment variable at EnvPGConnString is populated and the "integration" build tag is provided, then the value of that environment variable is used instead of an embedded postgres binary.

This function is meant to be called from TestMain like so:

func TestMain(m *testing.M) {
	var c int
	defer func() { os.Exit(c) }()
	defer integration.DBSetup()()
	c = m.Run()
}

func NeedDB added in v0.5.0

func NeedDB(t testing.TB)

NeedDB is like Skip, except that the test will run if the needed binaries have been fetched.

func Skip

func Skip(t testing.TB)

Skip will skip the current test or benchmark if this package was built without the "integration" build tag.

This should be used as an annotation at the top of the function, like (*testing.T).Parallel().

func TestThatTouchesNetwork(t *testing.T) {
	t.Parallel()
	integration.Skip(t)
	// ...
}

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB is a handle for connecting to an cleaning up a created database.

func NewDB

func NewDB(ctx context.Context, t testing.TB) (*DB, error)

NewDB generates a unique database instance for use in concurrent integration tests.

An environment variable maybe use to provide the root connection string used to generate a test specific database.

If no environment variable is specified the root connection string defaults to our local development db connection string DefaultDSN.

func (*DB) Close

func (db *DB) Close(ctx context.Context, t testing.TB)

Close tears down the created database.

func (*DB) Config

func (db *DB) Config() *pgxpool.Config

Config returns a pgxpool.Config for the created database.

type Engine added in v0.5.0

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

func (*Engine) Start added in v0.5.0

func (e *Engine) Start(t testing.TB) error

func (*Engine) Stop added in v0.5.0

func (e *Engine) Stop() error

Jump to

Keyboard shortcuts

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