testutil

package
v0.0.0-...-30f3625 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSpanner

func IsSpanner[DB WithDriver](db *sql.DB) bool

IsSpanner returns true of the db is a spanner db.

func IsSqlite

func IsSqlite[DB WithDriver](db *sql.DB) bool

IsSqlite returns true of the db is a sqlite db.

func RecreateSchema

func RecreateSchema(t *testing.T, db SchemaHandler)

RecreateSchema will drop and recreate schema. Will try it with multiple times with increased sleep time. To void errors like "Schema change operation rejected because a concurrent schema change operation or read-write transaction is already in progress.".

func RecreateSchemaOnce

func RecreateSchemaOnce(db SchemaHandler) (err error)

RecreateSchemaOnce will drop and recreate schema.

func RunDBTest

func RunDBTest[T TestDB](t *testing.T, open func(driver, source string) (db T, err error), callback func(t *testing.T, db T))

Types

type SchemaHandler

type SchemaHandler interface {
	Schema() []string
	DropSchema() []string
	Exec(query string, args ...any) (sql.Result, error)
}

SchemaHandler contains methods required for a schema recreation.

type T

type T struct {
	*testing.T
	// contains filtered or unexported fields
}

func Wrap

func Wrap(t *testing.T) *T

func (*T) Assert

func (t *T) Assert(that bool)

func (*T) AssertContains

func (t *T) AssertContains(msg, needle string)

func (*T) AssertError

func (t *T) AssertError(err error, msg string)

func (*T) AssertNoError

func (t *T) AssertNoError(err error)

func (*T) Context

func (t *T) Context(name string, val string)

func (*T) Run

func (t *T) Run(name string, f func(*T)) bool

func (*T) Runp

func (t *T) Runp(name string, f func(*T)) bool

type TestDB

type TestDB interface {
	io.Closer

	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

type WithDriver

type WithDriver interface {
	Driver() driver.Driver
}

WithDriver represents a DB which has a driver (usually *sql.DB).

Jump to

Keyboard shortcuts

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