dbtest

package
v0.0.0-...-51ed351 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FloatPointer

func FloatPointer(f float64) *float64

FloatPointer is a helper to get a *float64 from a float64. 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 a 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 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.

Types

type CoreAPIs

type CoreAPIs struct {
	User *user.Core
}

CoreAPIs represents all the core api's needed for testing.

type Test

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

Test owns state for running and shutting down tests.

func NewTest

func NewTest(t *testing.T, c *docker.Container) *Test

NewTest 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 (*Test) Token

func (test *Test) Token(email string, 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