Documentation
¶
Overview ¶
Package dbtest composes storage providers for tests that need a real database without putting provider construction back into package database.
Index ¶
- func CloseDatabase(db *database.Database) error
- func NewDatabase(tb testing.TB, config *database.Config) (*database.Database, error)
- func NewDatabaseWithOptions(tb testing.TB, opts Options) (*database.Database, error)
- func RawSQLiteMetadata(tb testing.TB, db *database.Database) (*sql.DB, error)
- type Options
- type StorageProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseDatabase ¶
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 ¶
NewDatabase composes Badger and SQLite for a test. The database is closed before its provider host during the cleanup registered with tb.
func NewDatabaseWithOptions ¶
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
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 ¶
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.