Documentation
¶
Overview ¶
Package testing contains internal testing utilities we apply in go-dbkit.
Index ¶
- Constants
- func DeadlockTest(t *testing.T, dialect dbkit.Dialect, checkDeadlockErr func(err error) bool)
- func MustRunAndOpenTestDB(ctx context.Context, dialect string) (db *sql.DB, stop func(ctx context.Context) error)
- func RunAndOpenTestDB(ctx context.Context, dialect string) (db *sql.DB, stop func(ctx context.Context) error, err error)
- type TestDB
Constants ¶
const ( PostgresImage = "postgres:16.15-alpine" MySQLImage = "mysql:8.4.13" MariaDBImage = "mariadb:11.4.13" MSSQLImage = "mcr.microsoft.com/mssql/server:2022-CU27-ubuntu-22.04" )
Container images of test databases. Tags are pinned to exact versions.
const DialectMariaDB = "mariadb"
DialectMariaDB selects a MariaDB server for RunTestDB. It uses the dbkit "mysql" dialect and driver.
Variables ¶
This section is empty.
Functions ¶
func DeadlockTest ¶
DeadlockTest is internal function to simulate DB deadlock
func MustRunAndOpenTestDB ¶
func MustRunAndOpenTestDB(ctx context.Context, dialect string) (db *sql.DB, stop func(ctx context.Context) error)
MustRunAndOpenTestDB creates a container with a test database and returns a connection to it.
func RunAndOpenTestDB ¶
func RunAndOpenTestDB(ctx context.Context, dialect string) (db *sql.DB, stop func(ctx context.Context) error, err error)
RunAndOpenTestDB starts a container with a test database for the dialect and returns a connection to it. See RunTestDB for supported dialects and failure handling.
Types ¶
type TestDB ¶ added in v0.18.0
type TestDB struct {
DriverName string
DSN string
// Stop terminates the container.
Stop func(ctx context.Context) error
}
TestDB is a running test database.
func RunTestDB ¶ added in v0.18.0
RunTestDB starts a container with a test database for the dialect and waits until PingContext succeeds. Supported dialects: "postgres" (lib/pq driver), "pgx", "mysql" (MySQL server, InnoDB, parseTime=true), "mariadb" (MariaDB server, "mysql" driver, InnoDB, parseTime=true) and "mssql" (SQL Server, "sqlserver" driver). The caller registers the database driver. Startup and readiness are bounded by timeouts derived from ctx. On failure the container is terminated and the error contains the image and the container log tail.