dbtest

package
v0.70.6 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package dbtest composes storage providers for tests that need a real database without putting provider construction back into package database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseDatabase

func CloseDatabase(db *database.Database) error

CloseDatabase closes a test database and its provider host in dependency order. Use it when a test must close a database before its cleanup phase.

func NewDatabase

func NewDatabase(
	tb testing.TB,
	config *database.Config,
) (*database.Database, error)

NewDatabase composes Badger and SQLite for a test. The database is closed before its provider host during the cleanup registered with tb.

func NewDatabaseWithOptions

func NewDatabaseWithOptions(
	tb testing.TB,
	opts Options,
) (*database.Database, error)

NewDatabaseWithOptions composes the selected storage providers for a test. It registers the chosen providers on a fresh host, resolves them with the supplied dependencies (including run mode and metadata connection pool size), and injects the resulting stores into a database. The database is closed before its provider host during the cleanup registered with tb.

func RawSQLiteMetadata added in v0.69.0

func RawSQLiteMetadata(
	tb testing.TB,
	db *database.Database,
) (*sql.DB, error)

RawSQLiteMetadata opens a repository-internal database/sql fixture against the metadata file owned by db. It exists only for tests that must seed a deliberately impossible or partially-upgraded state that the public store contract cannot represent. Production code must use MetadataStore methods.

Types

type Options

type Options struct {
	Config         *database.Config
	Blob           StorageProvider
	Metadata       StorageProvider
	RunMode        string
	MaxConnections int

	// InMemoryMetadata opts out of the migrated SQLite template (see
	// template.go) and builds the metadata store the old way: a fresh
	// shared-cache in-memory database with the full migration run against
	// it. That costs ~1.7s per call under -race, so use it only for a test
	// that genuinely depends on in-memory semantics rather than on a
	// file-backed database -- WAL behavior, locking, or the absence of a
	// data directory. Ignored unless the metadata provider is sqlite and
	// the caller supplied no Metadata.Config of its own. Options.Config
	// does not disable it: with a DataDir the template is seeded into
	// that directory instead.
	InMemoryMetadata bool
}

Options configures a test database. The zero value composes the badger blob store and the sqlite metadata store with an unset run mode, matching NewDatabase.

type StorageProvider

type StorageProvider struct {
	Name     string
	Config   map[string]any
	Register func(*plugin.Host) error
}

StorageProvider selects a storage provider by name, supplies its provider-specific config, and names the registrar that installs it on the test host. A zero value selects the always-built default for its capability (badger for blob, sqlite for metadata). Register must be set for any non-default provider, such as the tag-gated cloud blob stores.

Jump to

Keyboard shortcuts

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