testutils

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CheckViolationErrorCode   string = "check_violation"
	FKViolationErrorCode      string = "foreign_key_violation"
	NotNullViolationErrorCode string = "not_null_violation"
	UniqueViolationErrorCode  string = "unique_violation"
)
View Source
const MockSQLTransformerError = "ERROR"

Variables

View Source
var ErrMockSQLTransformer = errors.New("SQL transformer error")

Functions

func SharedTestMain

func SharedTestMain(m *testing.M, postRunHooks ...func() error)

SharedTestMain starts a postgres container to be used by all tests in a package. Each test then connects to the container and creates a new database. Optional functions that will run after all tests can be added and should return a nil error to indicate they ran successfully. If they return an error all subsequent functions will be skipped.

func TestSchema

func TestSchema() string

TestSchema returns the schema in which migration tests apply migrations. By default, migrations will be applied to the "public" schema.

func WithConnectionToContainer

func WithConnectionToContainer(t *testing.T, fn func(*sql.DB, string))

func WithMigratorAndConnectionToContainer

func WithMigratorAndConnectionToContainer(t *testing.T, fn func(mig *roll.Roll, db *sql.DB))

func WithMigratorAndConnectionToContainerWithOptions

func WithMigratorAndConnectionToContainerWithOptions(t *testing.T, opts []roll.Option, fn func(mig *roll.Roll, db *sql.DB))

func WithMigratorAndStateAndConnectionToContainerWithOptions

func WithMigratorAndStateAndConnectionToContainerWithOptions(t *testing.T, opts []roll.Option, fn func(*roll.Roll, *state.State, *sql.DB))

func WithMigratorInSchemaAndConnectionToContainer

func WithMigratorInSchemaAndConnectionToContainer(t *testing.T, schema string, fn func(mig *roll.Roll, db *sql.DB))

func WithMigratorInSchemaAndConnectionToContainerWithOptions

func WithMigratorInSchemaAndConnectionToContainerWithOptions(t testing.TB, schema string, opts []roll.Option, fn func(mig *roll.Roll, db *sql.DB))

func WithStateAndConnectionToContainer

func WithStateAndConnectionToContainer(t *testing.T, fn func(*state.State, *sql.DB))

func WithStateInSchemaAndConnectionToContainer

func WithStateInSchemaAndConnectionToContainer(t *testing.T, schema string, fn func(*state.State, *sql.DB))

func WithUninitializedState

func WithUninitializedState(t *testing.T, fn func(*state.State))

Types

type MockSQLTransformer

type MockSQLTransformer struct {
	// contains filtered or unexported fields
}

func NewMockSQLTransformer

func NewMockSQLTransformer(ts map[string]string) *MockSQLTransformer

NewMockSQLTransformer creates a MockSQLTransformer with the given transformations. The transformations map is a map of input SQL to output SQL. If the output SQL is "ERROR", the transformer will return an error on that input.

func (*MockSQLTransformer) TransformSQL

func (s *MockSQLTransformer) TransformSQL(sql string) (string, error)

TransformSQL transforms the given SQL string according to the transformations provided to the MockSQLTransformer. If the input SQL is not in the transformations map, the input SQL is returned unchanged.

Jump to

Keyboard shortcuts

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