test

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV_DBDRIVER = "SQLIZE_TSTDB_DRIVER"
	ENV_DBSOURCE = "SQLIZE_TSTDB_SOURCE"
)
View Source
const CRUDOps = CreateOp | ReadOp | UpdateOp | DeleteOp
View Source
const OpsErrorFmt = "Expected operations %s, got %s"

Variables

This section is empty.

Functions

func DBOpen

func DBOpen(t *testing.T, opts *DBOptions) (db sqlize.DB, err error)

func Example

func Example()

func LoggingDriver added in v0.2.0

func LoggingDriver(driver string) string

func MustDBOpen

func MustDBOpen(t *testing.T, opts *DBOptions) sqlize.DB

func OpenArgs added in v0.5.0

func OpenArgs(opts *DBOptions) (driver, dataSource string)

func RegisterLogging added in v0.2.0

func RegisterLogging(name string, driver driver.Driver)

func StdDBPtr added in v0.5.0

func StdDBPtr(db sqlize.DB) *sql.DB

func Test added in v0.2.0

func Test(ctx context.Context) *testing.T

func Truncate

func Truncate(db sqlize.Querier, tables ...bsq.Tabler) error

func WithTest added in v0.2.0

func WithTest(ctx context.Context, t *testing.T) context.Context

Types

type CRUDOperation

type CRUDOperation int
const (
	CreateOp CRUDOperation = (1 << iota)
	ReadOp
	UpdateOp
	DeleteOp
)

func (CRUDOperation) All

func (ops CRUDOperation) All(test CRUDOperation) bool

func (CRUDOperation) Any

func (ops CRUDOperation) Any(test CRUDOperation) bool

func (CRUDOperation) String

func (ops CRUDOperation) String() string

type CRUDTest added in v0.3.0

type CRUDTest[E sqlize.Entity[ID], ID sqlize.EntityID] struct {
	// WriteObj is set by test code and then written to the DB
	WriteObj E
	// ReadObj is read from DB to be compared with the WriteObj
	ReadObj E
	// Chage is used to modify the WriteObj to check updates
	Change ChangeFunc
	// If Equal is not nil it is used to compare WriteObj and ReadObj. Otherwise
	// the objects are compared with reflect.DeepEqual().
	Equal func() bool
	// The Repo that handles the CRUD operations
	Repo sqlize.Repo[E, ID]
}

func (*CRUDTest[E, ID]) Run added in v0.3.0

func (ct *CRUDTest[E, ID]) Run(t *testing.T, db sqlize.Querier) (res CRUDOperation)

type ChangeFunc

type ChangeFunc = func() (desc string, cont bool)

ChangeFunc is used in CRUDTests to modify the write object and see if the written change is successfully read back. Changing the write object will be repeated until the ChangeFunc retuns chainNext == nil. Otherwise chainNext will be passed to the next call of the ChangeFunc.

type DBOptions

type DBOptions struct {
	LogSQL bool
	Driver string
	Source string
}

type Logger added in v0.2.0

type Logger struct {
	sqlmw.NullInterceptor
}

func (Logger) ConnBeginTx added in v0.2.0

func (l Logger) ConnBeginTx(
	ctx context.Context,
	conn driver.ConnBeginTx,
	opts driver.TxOptions,
) (context.Context, driver.Tx, error)

func (Logger) ConnExecContext added in v0.2.0

func (l Logger) ConnExecContext(
	ctx context.Context,
	conn driver.ExecerContext,
	query string,
	args []driver.NamedValue,
) (driver.Result, error)

func (Logger) ConnPrepareContext added in v0.2.0

func (l Logger) ConnPrepareContext(
	ctx context.Context,
	conn driver.ConnPrepareContext,
	query string,
) (context.Context, driver.Stmt, error)

func (Logger) ConnQueryContext added in v0.2.0

func (l Logger) ConnQueryContext(
	ctx context.Context,
	conn driver.QueryerContext,
	query string,
	args []driver.NamedValue,
) (context.Context, driver.Rows, error)

func (Logger) StmtExecContext added in v0.2.0

func (l Logger) StmtExecContext(
	ctx context.Context,
	conn driver.StmtExecContext,
	query string,
	args []driver.NamedValue,
) (driver.Result, error)

func (Logger) StmtQueryContext added in v0.2.0

func (l Logger) StmtQueryContext(
	ctx context.Context,
	conn driver.StmtQueryContext,
	query string,
	args []driver.NamedValue,
) (context.Context, driver.Rows, error)

func (Logger) TxCommit added in v0.2.0

func (l Logger) TxCommit(ctx context.Context, tx driver.Tx) error

func (Logger) TxRollback added in v0.2.0

func (l Logger) TxRollback(ctx context.Context, tx driver.Tx) error

type Queries

type Queries struct {
	Test    *testing.T
	DB      sqlize.Querier
	Dialect bsq.Dialect
	// Note that RDBMS generally do not guarantee column order for good reasons.
	// Use this check for aesthetic reasons but DO NOT expect it for correctness.
	SameCoumnOrder bool
}

func (Queries) SelectAllColumns

func (qs Queries) SelectAllColumns(decl bsq.Tabler) (done bool)

func (Queries) SelectDeclaredColumns

func (qs Queries) SelectDeclaredColumns(decl bsq.Tabler) (done bool)

Jump to

Keyboard shortcuts

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