dbtest

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package dbtest provides a way to create a clean database for tests using template databases. For it to function properly a postgres database server must be running with the expected templates. This is typically done using the docker image provided in the docker directory of this package.

To use this package in a test add something like the following in the beginning of the test:

c, u, _, err := dbtest.StartUsingTemplate(dbtest.Postgres)
require.NoError(t, err)
t.Cleanup(func() {
  require.NoError(t, c())
})
// use u to get a connection to the new database
dBase, err := common.SqlOpen("postgres", u)

By default this uses a template that already has all of the boundary migrations run. If a test needs a database without any migrations, like in the case where the migration code needs to be tested, a different template can be specified. This should generally be template1:

c, u, _, err := dbtest.StartUsingTemplate(dbtest.Postgres, dbtest.WithTemplate(dbtest.Template1))

See https://www.postgresql.org/docs/13/manage-ag-templatedbs.html

Index

Constants

View Source
const (
	BoundaryTemplate                                 = "boundary_template"
	Template1                                        = "template1"
	Boundary1000Sessions10ConnsPerSession10Template  = "boundary_session_1000_10_10_template"
	Boundary1000Sessions10ConnsPerSession25Template  = "boundary_session_1000_10_25_template"
	Boundary1000Sessions10ConnsPerSession50Template  = "boundary_session_1000_10_50_template"
	Boundary1000Sessions10ConnsPerSession75Template  = "boundary_session_1000_10_75_template"
	Boundary1000Sessions10ConnsPerSession100Template = "boundary_session_1000_10_100_template"
	Boundary1000Sessions10ConnsPerSession500Template = "boundary_session_1000_10_500_template"
)

Template Database Names

View Source
const BoundaryBenchmarksUserPassword = "testpassword"

BoundaryBenchmarksUserPassword is the password used for all users created by the boundary benchmarks dump generator.

View Source
const (
	Postgres = "postgres"
)

Dialects

Variables

View Source
var StartUsingTemplate func(dialect string, opt ...Option) (func() error, string, string, error) = startUsingTemplate

StartUsingTemplate creates a new test database from a postgres template database.

Functions

func GetBoundaryBenchmarksRootKeyWrapper added in v0.8.0

func GetBoundaryBenchmarksRootKeyWrapper(ctx context.Context) (wrapping.Wrapper, error)

GetBoundaryBenchmarksRootKeyWrapper returns the root key wrapper used for the benchmark dumps.

Types

type Option

type Option func(*Options)

Option - how Options are passed as arguments.

func WithTemplate

func WithTemplate(template string) Option

WithTemplate tells the command with database template to use when creating a new test database.

type Options

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

Options - how Options are represented.

func GetOpts

func GetOpts(opt ...Option) Options

GetOpts - iterate the inbound Options and return a struct.

Jump to

Keyboard shortcuts

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