dbtest

package
v0.0.0-...-39283cd Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 24 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 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 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.

func UnitTest

func UnitTest(t *testing.T, table []UnitTable, testName string)

UnitTest performs the actual test logic based on the table data.

Types

type BusDomain

type BusDomain struct {
	Delegate *delegate.Delegate
	Home     *homebus.Core
	Product  *productbus.Core
	User     *userbus.Core
	VProduct *vproductbus.Core
}

BusDomain represents all the business domain apis needed for testing.

type SeedData

type SeedData struct {
	Users  []User
	Admins []User
}

SeedData represents data that was seeded for the test.

type Test

type Test struct {
	DB        *sqlx.DB
	Log       *logger.Logger
	Auth      *auth.Auth
	BusDomain BusDomain
	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, testName string) *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 (tst *Test) Token(email string) string

Token generates an authenticated token for a user.

type UnitTable

type UnitTable struct {
	Name    string
	ExpResp any
	ExcFunc func(ctx context.Context) any
	CmpFunc func(got any, exp any) string
}

UnitTable represent fields needed for running an unit test.

type User

type User struct {
	userbus.User
	Token    string
	Products []productbus.Product
	Homes    []homebus.Home
}

User represents an app user specified for the test.

Jump to

Keyboard shortcuts

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