testutil

package
v0.62.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DoltDockerImage = "dolthub/dolt-sql-server:1.83.0"

DoltDockerImage is the Docker image used for Dolt test containers.

Variables

This section is empty.

Functions

func CleanTestBranches

func CleanTestBranches(db *sql.DB, database string)

CleanTestBranches removes stale test branches left by crashed tests. Call this in TestMain after creating the shared database.

func DoltContainerAddr

func DoltContainerAddr() string

DoltContainerAddr returns the address (host:port) of the Dolt container.

func DoltContainerCrashError

func DoltContainerCrashError() error

DoltContainerCrashError returns an error if the shared container has exited unexpectedly, nil otherwise.

func DoltContainerCrashed

func DoltContainerCrashed() bool

DoltContainerCrashed returns true if the shared container has exited unexpectedly. Returns false if no container was started.

func DoltContainerPort

func DoltContainerPort() string

DoltContainerPort returns the mapped host port of the Dolt container.

func DoltContainerPortInt

func DoltContainerPortInt() int

DoltContainerPortInt returns the mapped host port as an int.

func EnsureDoltContainerForTestMain

func EnsureDoltContainerForTestMain() error

EnsureDoltContainerForTestMain starts a shared Dolt container for use in TestMain functions. Call TerminateDoltContainer() after m.Run() to clean up. Sets BEADS_DOLT_PORT process-wide.

func FindFreePort

func FindFreePort() (int, error)

FindFreePort finds an available TCP port by binding to :0.

func ForceRepoLocalHooksPath

func ForceRepoLocalHooksPath(repoDir string) error

ForceRepoLocalHooksPath configures a git test repository to use .git/hooks regardless of any global core.hooksPath configuration.

func RequireDoltContainer

func RequireDoltContainer(t *testing.T)

RequireDoltContainer ensures a shared Dolt container is running. Skips the test if Docker is not available.

func ResetTestBranch

func ResetTestBranch(t *testing.T, db *sql.DB)

ResetTestBranch resets the current branch's working set back to HEAD, discarding all uncommitted changes. Use this in table-driven tests to restore seed data state between subtests, avoiding the overhead of creating a new branch for each subtest.

Usage pattern:

branch, cleanup := StartTestBranch(t, db, database)
// ... seed data, then DOLT_COMMIT to set HEAD ...
for _, tc := range testCases {
    // ... run test case that modifies data ...
    ResetTestBranch(t, db) // reset to seed state
}

func SetupSharedTestDB

func SetupSharedTestDB(port int, dbName string) (*sql.DB, error)

SetupSharedTestDB creates a shared database on the test Dolt server with committed schema for branch-per-test isolation. Call from TestMain after EnsureDoltContainerForTestMain. Returns the database name and a raw *sql.DB handle for branch cleanup.

The schema is committed to main so that DOLT_BRANCH creates COW snapshots of the full schema. Each test then branches from main with StartTestBranch.

func StartIsolatedDoltContainer

func StartIsolatedDoltContainer(t *testing.T) string

StartIsolatedDoltContainer starts a per-test Dolt container and returns the mapped host port. The container is terminated automatically when the test finishes.

func StartTestBranch

func StartTestBranch(t *testing.T, db *sql.DB, database string) (branchName string, cleanup func())

StartTestBranch creates an isolated Dolt branch for a single test. It creates a branch from HEAD of the given database, checks it out on the current connection, and returns the branch name and a cleanup function.

IMPORTANT: The db must have MaxOpenConns(1) to ensure DOLT_CHECKOUT affects all queries (it's session-level, and each pooled connection is a separate session).

The cleanup function switches back to main and deletes the branch.

func TempDirInMemory

func TempDirInMemory(t testing.TB) string

TempDirInMemory creates a temporary directory that preferentially uses in-memory filesystems (tmpfs/ramdisk) when available. This reduces I/O overhead for git-heavy tests.

On Linux: Uses /dev/shm if available (tmpfs ramdisk) On macOS: Falls back to standard temp (ramdisks require manual setup) On Windows: Falls back to standard temp

The directory is automatically cleaned up when the test ends.

func TerminateDoltContainer

func TerminateDoltContainer()

TerminateDoltContainer stops and removes the shared Dolt container. Called from TestMain after m.Run().

func WaitForServer

func WaitForServer(port int, timeout time.Duration) bool

WaitForServer polls until the server accepts TCP connections on the given port.

Types

This section is empty.

Directories

Path Synopsis
Package fixtures provides realistic test data generation for benchmarks and tests.
Package fixtures provides realistic test data generation for benchmarks and tests.

Jump to

Keyboard shortcuts

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