Documentation
¶
Index ¶
- Constants
- func CleanTestBranches(db *sql.DB, database string)
- func DoltContainerAddr() string
- func DoltContainerCrashError() error
- func DoltContainerCrashed() bool
- func DoltContainerPort() string
- func DoltContainerPortInt() int
- func EnsureDoltContainerForTestMain() error
- func FindFreePort() (int, error)
- func ForceRepoLocalHooksPath(repoDir string) error
- func RequireDoltContainer(t *testing.T)
- func ResetTestBranch(t *testing.T, db *sql.DB)
- func SetupSharedTestDB(port int, dbName string) (*sql.DB, error)
- func StartIsolatedDoltContainer(t *testing.T) string
- func StartTestBranch(t *testing.T, db *sql.DB, database string) (branchName string, cleanup func())
- func TempDirInMemory(t testing.TB) string
- func TerminateDoltContainer()
- func WaitForServer(port int, timeout time.Duration) bool
Constants ¶
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 ¶
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 ¶
FindFreePort finds an available TCP port by binding to :0.
func ForceRepoLocalHooksPath ¶
ForceRepoLocalHooksPath configures a git test repository to use .git/hooks regardless of any global core.hooksPath configuration.
func RequireDoltContainer ¶
RequireDoltContainer ensures a shared Dolt container is running. Skips the test if Docker is not available.
func ResetTestBranch ¶
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 ¶
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 ¶
StartIsolatedDoltContainer starts a per-test Dolt container and returns the mapped host port. The container is terminated automatically when the test finishes.
func StartTestBranch ¶
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 ¶
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().
Types ¶
This section is empty.