testdb

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package testdb opens the database that package tests run against. It imports only pkg/migrations (and, through it, pkg/models and pkg/identifiers) and pkg/sqliteconn, so tests in every other package can use it without an import cycle, including the packages pkg/testutils imports. The internal tests of pkg/migrations, pkg/models, and pkg/identifiers are the exception: they would import their own package through this one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddQueryHook added in v0.3.0

func AddQueryHook(t testing.TB, db *bun.DB, hook bun.QueryHook)

AddQueryHook attaches hook to db, which must come from New or NewShared.

Tests often add a hook after building the services under test, which hold db already. bun's WithQueryHook returns a copy those services never use, so every database from open carries a forwardHook from the start, and this adds hook to it in place.

func New

func New(t testing.TB) *bun.DB

New returns an in-memory SQLite database migrated to the latest schema, with foreign keys on, that is closed when the test ends. Each call returns a separate database, so parallel tests do not share rows. The pool holds one connection, as pkg/database does in production.

func NewShared added in v0.2.0

func NewShared(t testing.TB) *bun.DB

NewShared is New without the one-connection cap, for tests whose code runs queries from several goroutines at once, such as the worker.

Types

This section is empty.

Jump to

Keyboard shortcuts

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