testing

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testing contains internal testing utilities we apply in go-dbkit.

Index

Constants

View Source
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.

View Source
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

func DeadlockTest(t *testing.T, dialect dbkit.Dialect, checkDeadlockErr func(err error) bool)

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

func RunTestDB(ctx context.Context, dialect string) (res *TestDB, err error)

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.

Jump to

Keyboard shortcuts

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