testingsuite

package
v0.0.0-...-39c0a64 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringWithCharset

func StringWithCharset(length int, charset string) string

StringWithCharset returns a random string https://www.calhoun.io/creating-random-strings-in-go/

Types

type BaseTestSuite

type BaseTestSuite struct {
	suite.Suite
}

BaseTestSuite is a suite for testing

func (*BaseTestSuite) FatalFalse

func (suite *BaseTestSuite) FatalFalse(b bool, messages ...string)

FatalFalse ends a test if a value is not false

func (*BaseTestSuite) FatalNil

func (suite *BaseTestSuite) FatalNil(object interface{}, messages ...string)

FatalNil ends a test if an object is not nil

func (*BaseTestSuite) FatalNoError

func (suite *BaseTestSuite) FatalNoError(err error, messages ...string)

FatalNoError ends a test if an error is not nil

func (*BaseTestSuite) FatalNotNil

func (suite *BaseTestSuite) FatalNotNil(object interface{}, messages ...string)

FatalNotNil ends a test if an object is nil

func (*BaseTestSuite) FatalTrue

func (suite *BaseTestSuite) FatalTrue(b bool, messages ...string)

FatalTrue ends a test if a value is not true

type PackageName

type PackageName string

PackageName represents the project-relative name of a Go package.

func CurrentPackage

func CurrentPackage() PackageName

CurrentPackage returns the project-relative name of the caller's package.

"github.com/transcom/mymove/pkg/" is removed from the beginning of the absolute package name, so the return value will be e.g. "handlers/internalapi".

func (PackageName) String

func (pn PackageName) String() string

func (PackageName) Suffix

func (pn PackageName) Suffix(suffix string) PackageName

Suffix returns a new PackageName with an underscore and the suffix appended to the end suffix should be a snake case string

type PopTestSuite

type PopTestSuite struct {
	BaseTestSuite
	PackageName
	// contains filtered or unexported fields
}

PopTestSuite is a suite for testing

func NewPopTestSuite

func NewPopTestSuite(packageName PackageName, opts ...PopTestSuiteOption) *PopTestSuite

NewPopTestSuite returns a new PopTestSuite

func (*PopTestSuite) AppContextForTest

func (suite *PopTestSuite) AppContextForTest() appcontext.AppContext

AppContextForTest returns the AppContext for the test suite

func (*PopTestSuite) AppContextWithSessionForTest

func (suite *PopTestSuite) AppContextWithSessionForTest(session *auth.Session) appcontext.AppContext

AppContextWithSessionForTest returns the AppContext for the test suite

func (*PopTestSuite) DB

func (suite *PopTestSuite) DB() *pop.Connection

DB returns a db connection. It has logic to handle per test transactions, both when PreloadData is called and when it is not

func (*PopTestSuite) FatalNoVerrs

func (suite *PopTestSuite) FatalNoVerrs(verrs *validate.Errors, messages ...string)

FatalNoVerrs ends a test if there are verrs

func (*PopTestSuite) Logger

func (suite *PopTestSuite) Logger() *zap.Logger

Logger returns the logger for the test suite

func (*PopTestSuite) MustCreate

func (suite *PopTestSuite) MustCreate(model interface{})

MustCreate requires creating without errors

func (*PopTestSuite) MustDestroy

func (suite *PopTestSuite) MustDestroy(model interface{})

MustDestroy requires deleting without errors

func (*PopTestSuite) MustSave

func (suite *PopTestSuite) MustSave(model interface{})

MustSave requires saving without errors

func (*PopTestSuite) NilOrNoVerrs

func (suite *PopTestSuite) NilOrNoVerrs(err error)

NilOrNoVerrs checks that an error is effecively nil

func (*PopTestSuite) NoVerrs

func (suite *PopTestSuite) NoVerrs(verrs *validate.Errors) bool

NoVerrs prints any errors it receives

func (*PopTestSuite) PreloadData

func (suite *PopTestSuite) PreloadData(f func())

PreloadData sets up the data used by all subtests. It can only be called once. Once it is called, all subtests will use the same database, but will run inside a savepoint that are rolled back. This way each subtest can reuse the preloaded data, but each subtest cannot modify the data used by another test.

Note that calling PreloadData automatically changes how suite.Run works

func (*PopTestSuite) TearDown

func (suite *PopTestSuite) TearDown()

TearDown runs the teardown for step for the suite Important steps are to close open DB connections and drop the DB

func (*PopTestSuite) TearDownTest

func (suite *PopTestSuite) TearDownTest()

TearDownTest runs the teardown per test. It will only do something useful if per test transactions are enabled

func (*PopTestSuite) Truncate

func (suite *PopTestSuite) Truncate(tables []string) error

Truncate deletes all data from the specified tables.

func (*PopTestSuite) TruncateAll

func (suite *PopTestSuite) TruncateAll() error

TruncateAll deletes all data from all tables that are owned by the user connected to the database.

type PopTestSuiteOption

type PopTestSuiteOption func(*PopTestSuite)

PopTestSuiteOption is type intended to be used to change a PopTestSuite object.

func WithHighPrivPSQLRole

func WithHighPrivPSQLRole() PopTestSuiteOption

WithHighPrivPSQLRole is a functional option that can be passed into the NewPopTestSuite function to create a PopTestSuite that only uses the privileged SQL connection.

func WithPerTestTransaction

func WithPerTestTransaction() PopTestSuiteOption

Jump to

Keyboard shortcuts

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