dbtest

package
v0.11.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package dbtest has utilities to help with writing DB related tests in conjunction with sqlize.

Index

Constants

View Source
const (
	ENV_DBDRIVER = "SQLIZE_TESTDB_DRIVER"
	ENV_DBSOURCE = "SQLIZE_TESTDB_SOURCE"
)

Variables

View Source
var ExampleTB exampleTB

Functions

func DriverName

func DriverName(t TB, fallback string) string

func NewLogger

func NewLogger(t interface{ Logf(string, ...any) }) sqlize.Logger

NewLogger creates a new logger to be used with sqlize.LogDriver. For an example read the test TestNewLogger.

func Open

func Open(t *testing.T, drv driver.Driver, source string, log sqlize.LogFlag) (*sql.DB, error)

func OpenArgs

func OpenArgs(t TB, drvFallback, srcFallback string) (driver, source string)

func ShallOpen added in v0.8.3

func ShallOpen(t *testing.T, drv driver.Driver, source string, log sqlize.LogFlag) *sql.DB

func SourceName

func SourceName(t TB, fallback string) string

func VerifyTable

func VerifyTable(t testing.TB, cmd sqlize.CtxCmd, tbl *bsq.Table, d Dialect) (ok bool)

func VerifyTables

func VerifyTables(t testing.TB, db *bsq.Model, cmd sqlize.CtxCmd, d Dialect) bool

Types

type CRUDTest

type CRUDTest[E entity.Entity[I], I entity.ID] struct {
	Repo         entity.Repo[E, I]
	Create, Read *E
	Equal        func(e, f *E) error
	// contains filtered or unexported fields
}

func (CRUDTest[E, I]) Run

func (crud CRUDTest[E, I]) Run(t *testing.T, db sqlize.CtxCmd)

func (CRUDTest[E, I]) Update

func (crud CRUDTest[E, I]) Update(name string, mod func(*E)) CRUDTest[E, I]

type Dialect added in v0.9.2

type Dialect interface {
	SQLSelect1Row(table string) string
}

type FieldDiff added in v0.9.0

type FieldDiff []error

func FieldEq added in v0.9.0

func FieldEq[F comparable](e FieldDiff, hint string, l, r F) FieldDiff

func FieldEqual added in v0.9.0

func FieldEqual[F interface{ Equal(F) bool }](e FieldDiff, hint string, l, r F) FieldDiff

func (FieldDiff) Error added in v0.9.0

func (d FieldDiff) Error() error

type TB added in v0.8.8

type TB interface {
	Log(args ...any)
	Error(args ...any)
}

TB has a subset of methods from testing.TB. It is implemented by [Errorer].

Jump to

Keyboard shortcuts

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