testdb

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 5 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 testdb opens SQLite files for tests the way production does.

Tests that open their own database with a different DSN (no WAL, no busy timeout, an unlimited pool) fail under CPU and disk load in ways production never does. Use Open and Reopen instead of sql.Open in a test.

This package imports no other package of this module, so any test package can use it without an import cycle. For that reason it cannot call the production DSN builder (dash.dsn, which is private and sits in a package that imports store). It copies the pragmas of dash/store.go dsn. tooldefer/file.go Open uses the first 3 of them. Keep them equal to dash/store.go dsn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DSN

func DSN(path string) string

DSN returns the dash DSN for a file path (dash/store.go dsn): busy_timeout first (the driver runs the pragmas in order, and journal_mode needs a lock), then WAL, synchronous NORMAL, foreign keys and incremental auto_vacuum. The last 2 are inert for the store and tooldefer schemas.

func Open

func Open(t testing.TB, path string) *sql.DB

Open opens the SQLite file at path with the production settings. It closes the database when the test ends. It fails the test with the real error.

func OpenUnchecked

func OpenUnchecked(t testing.TB, path string) *sql.DB

OpenUnchecked is Open without the first connection. It is for a test that opens a broken file (corrupt, unwritable, read-only) on purpose and checks how the code under test fails. It never fails the test on a bad file.

func Reopen

func Reopen(t testing.TB, db *sql.DB, path string) *sql.DB

Reopen closes db, waits for the close to finish, and opens the same file again. Use it in a restart test. Close returns only after every connection is closed, so the second open sees the file as the first left it, with the WAL checkpointed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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