dbtest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package dbtest contains supporting code for running tests that hit the DB.

Index

Constants

View Source
const (
	Success = "\u2713"
	Failed  = "\u2717"
)

Success and failure markers.

Variables

This section is empty.

Functions

func BoolPointer

func BoolPointer(b bool) *bool

BoolPointer is a helper to get a *bool from a bool. It is in the tests package because we normally don't want to deal with pointers to basic types, but it's useful in some tests.

func IntPointer

func IntPointer(i int) *int

IntPointer is a helper to get a *int from an int. It is in the tests package because we normally don't want to deal with pointers to basic types, but it's useful in some tests.

func NewUnit

func NewUnit(t *testing.T, c *docker.Container, dbName string) (*zap.SugaredLogger, *sqlx.DB, func())

NewUnit creates a test database inside a Docker container. It creates the required table structure but the database is otherwise empty. It returns the database to use as well as a function to call at the end of the test.

func StartDB

func StartDB() (*docker.Container, error)

StartDB starts a database instance.

func StopDB

func StopDB(c *docker.Container)

StopDB stops a running database instance.

func StringPointer

func StringPointer(s string) *string

StringPointer is a helper to get a *string from a string. It is in the tests package because we normally don't want to deal with pointers to basic types, but it's useful in some tests.

func TimePointer

func TimePointer(t time.Time) *time.Time

TimePointer is a helper to get a *time.Time from a time.Time. It is in the tests package because we normally don't want to deal with pointers to basic types, but it's useful in some tests.

Types

type Test

type Test struct {
	DB       *sqlx.DB
	Log      *zap.SugaredLogger
	Auth     *auth.Auth
	Teardown func()
	// contains filtered or unexported fields
}

Test owns state for running and shutting down tests.

func NewIntegration

func NewIntegration(t *testing.T, c *docker.Container, dbName string) *Test

NewIntegration creates a database, seeds it, constructs an authenticator.

func (*Test) Token

func (test *Test) Token(email, pass string) string

Token generates an authenticated token for a user.

Jump to

Keyboard shortcuts

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