testutils

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ProjectRootFilePath = filepath.Join(filepath.Dir(b), "../..")
)

ProjectRootFilePath is a Golang-native mechanism to get the root of the package structure on the filesystem. With this, tests can introspect files (e.g. database changelogs) without needing to use relative paths themselves (which would be relative to the test file itself). H/T https://stackoverflow.com/a/58294680

Functions

func Cleanup

func Cleanup(t *testing.T, dbConn *gorm.DB)

Cleanup can be run immediately, or deferred with each test run so that we can ensure each case starts with a clean database

func ConnectAndMigrate

func ConnectAndMigrate(t *testing.T) *gorm.DB

ConnectAndMigrate will parse config to attempt to establish a connection to the test database It will cause the test to fail fatally if an error is encountered. It will then attempt to apply all migrations in /db/migrations to that database and will fail similarly if an error is encountered

func SetupTestContext

func SetupTestContext() (*gin.Context, *httptest.ResponseRecorder)

func Truncate

func Truncate(db *gorm.DB) error

Truncate cleans up tables after integration tests

Types

This section is empty.

Jump to

Keyboard shortcuts

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