drivertesting

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package drivertesting holds the shared driver test harness. Imported by each driver's integration test under a //go:build integration tag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunDriverSuite

func RunDriverSuite(t *testing.T, ctor func() driver.Driver, fx Fixtures)

RunDriverSuite exercises the full Driver contract against a real database. ctor returns the driver-under-test; fx provides the env.

Every driver should call this from a single TestSuite_<DriverName> integration test; that yields uniform coverage of:

  • Connect / Close
  • Inspect
  • Backup round-trip via Restore + VerifyRestore
  • Cancel propagation (ctx cancellation kills subprocess + no temp file)
  • Sentinel error mapping on bad credentials

Types

type Fixtures

type Fixtures struct {
	// Profile points at a freshly-started, empty test database.
	Profile driver.Profile

	// Seed runs arbitrary SQL/script to populate the test database with a
	// known fixture. Called before Backup.
	Seed func(ctx context.Context, db *sql.DB) error

	// VerifyRestore asserts the database state matches what Seed produced.
	// Called after Restore round-trips through Backup.
	VerifyRestore func(ctx context.Context, db *sql.DB) error

	// Cleanup tears down the test database. Called via t.Cleanup.
	Cleanup func()

	// SQLOpener returns a *sql.DB connected to the same database. Used by
	// Seed and VerifyRestore (they can't go through driver.Conn because
	// it doesn't expose raw SQL).
	SQLOpener func() (*sql.DB, error)
}

Fixtures describes everything a driver needs to be exercised by the shared RunDriverSuite. Drivers populate this struct from their own integration setup (e.g. testcontainers).

Jump to

Keyboard shortcuts

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