dbfixture

package
v1.0.10184-822ca07 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 17 Imported by: 2

Documentation

Overview

Package dbfixture will setup a and reset a fresh database for each of your tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Host string
	// User is intended as the superuser that is used to bootstrap a database instance for use
	User string
	// AppUser is intended as a reduced permission user that the application uses to interact with the database
	AppUser string
	// Password is intended as the password for the superuser that can modify db structure
	Password secret.String
	// AppPassword is intended as the password for the least-privileged application db user
	AppPassword secret.String
}

type Fixture

type Fixture struct {
	DBName   string
	Host     string
	User     string
	Password secret.String
	DB       *sqlx.DB
	TX       *db.TxManager
	Cleanup  func(ctx context.Context) error
	AdminDB  *sqlx.DB
	AdminTX  *db.TxManager
	// contains filtered or unexported fields
}

func SetupDB

func SetupDB(ctx context.Context, t types.TestingTB, schema string, con Connection) (db *Fixture)

func (*Fixture) Reset

func (f *Fixture) Reset(ctx context.Context) (err error)

type Manager

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

func NewManager

func NewManager(con Connection) (*Manager, error)

NewManager returns a DB manager

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) NewDB

func (m *Manager) NewDB(ctx context.Context, con Connection, dbName, schema string) (*Fixture, error)

NewDB returns a new database fixture. The database name is generated from dbName with a random suffix.

type NoDBError

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

func (*NoDBError) Error

func (e *NoDBError) Error() string

func (*NoDBError) Unwrap

func (e *NoDBError) Unwrap() error

type SharedFixture

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

func SetupSystem

func SetupSystem(t types.TestingTB, con Connection) *SharedFixture

SetupSystem prepares the running system for use callers should not rely on the fact this currently uses a package global

func (*SharedFixture) Manager

func (s *SharedFixture) Manager() *Manager

Jump to

Keyboard shortcuts

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