dbtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package dbtest gives each test a throwaway database of the dialect CHOK_TEST_DRIVER names: sqlite (the default; a file in t.TempDir, so the production pool layout is exercised), postgres (a fresh schema in the database of CHOK_TEST_PG_DSN) or mysql (a fresh chok_test_<rand> database on the server of CHOK_TEST_MYSQL_DSN). Cleanup drops it. A lane whose DSN is missing fails rather than silently skipping.

choktest.DB wraps it for applications; the batteries' own tests use it directly.

Index

Constants

View Source
const (
	DriverEnv   = "CHOK_TEST_DRIVER"
	PGDSNEnv    = "CHOK_TEST_PG_DSN"
	MySQLDSNEnv = "CHOK_TEST_MYSQL_DSN"
)

The environment of the database lanes.

Variables

This section is empty.

Functions

func Config

func Config(t testing.TB) db.Config

Config returns a db.Config pointing at a fresh database of the lane's dialect, migrate auto, which cleanup drops.

func Driver

func Driver() string

Driver is the lane's dialect: sqlite, postgres or mysql.

func Open

func Open(t testing.TB, opts ...db.Option) *db.DB

Open opens a fresh database with opts and closes it at cleanup.

func OpenConfig

func OpenConfig(t testing.TB, cfg db.Config, opts ...db.Option) *db.DB

OpenConfig opens cfg, typically Config(t) adjusted, and closes it at cleanup.

Types

This section is empty.

Jump to

Keyboard shortcuts

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