testutil

package
v0.0.0-...-5d14948 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

nolint: gosec

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DropAndRecreateDB

func DropAndRecreateDB(dbName string)

DropAndRecreateDB drops and recreates a given database.

func GetFileRuntimeDirectory

func GetFileRuntimeDirectory() string

Returns the directory of the file this function lives in.

func GetStderr

func GetStderr(t *testing.T, dir string) string

GetStderr returns the contents of stderr.txt in dir.

func NewDB

func NewDB(options ...TestDBOption) (*pgxpool.Pool, *sql.DB, error)

NewDB returns a new testing Postgres pool with up-to-date migrations. It is shared within the test suite package. Panics on any error encountered.

func NewLogger

func NewLogger(t *testing.T) *zap.SugaredLogger

func RandomBool

func RandomBool() bool

RandomBool generates a random boolean.

func RandomDate

func RandomDate() time.Time

RandomDate generates a random UTC date.

func RandomEmail

func RandomEmail() string

RandomEmail generates a random email.

func RandomFirstName

func RandomFirstName() string

RandomFirstName generates a random first name.

func RandomFrom

func RandomFrom[T any](items []T) T

RandomFrom selects a random item from a list. Assumes the list is not empty.

func RandomHEXColor

func RandomHEXColor() string

RandomHEXColor generates a random color in hexadecimal format (#RRGGBB).

func RandomInt

func RandomInt(min, max int) int

RandomInt generates a random int between min and max.

func RandomInt64

func RandomInt64(min, max int64) int64

RandomInt64 generates a random int64 between min and max.

func RandomLastName

func RandomLastName() string

RandomLastName generates a random last name.

func RandomLocalDate

func RandomLocalDate() time.Time

RandomDate generates a random local date.

func RandomMoney

func RandomMoney() int64

RandomMoney generates a random amount of money.

func RandomName

func RandomName() string

RandomName generates a random name.

func RandomNameIdentifier

func RandomNameIdentifier(n int, sep string) string

RandomNameIdentifier generates a random name identifier, such as eminently-sincere-mollusk-aksticpemgicjrtb. Prefix count is configurable via n.

func RandomString

func RandomString(n int) string

RandomString generates a random string of length n.

func Setup

func Setup()

Setup runs necessary pre-testing commands for a package: env vars loading, sourcing... It runs once for each suite.

Types

type TestDBOption

type TestDBOption func(*TestDBOptions)

func WithMigrations

func WithMigrations() TestDBOption

WithMigrations runs migrations on top of the database.

type TestDBOptions

type TestDBOptions struct {
	WithMigrations bool
}

Jump to

Keyboard shortcuts

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