dbtest

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 10 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.

Types

type Options

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

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