storagefake

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package storagefake provides a configurable double for storage.Database, storage.Transaction, and storage.DBTX, for tests that exercise real service/server composition or drive sqlc-generated queries without a live DB connection.

This lives in its own subpackage rather than directly under internal/testutil: pkg/storage (and pkg/base/pkg/config, which it depends on) already import internal/testutil from their own internal test files (for ChdirRepoRoot), so a FakeDatabase living there and importing pkg/storage would create an import cycle for those packages' tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Row

func Row(fn func(dest ...any) error) pgx.Row

Row returns a pgx.Row whose Scan delegates to fn.

func Rows

func Rows(scans ...func(dest ...any) error) pgx.Rows

Rows returns a pgx.Rows yielding one row per scan func, in order.

Types

type FakeDatabase

type FakeDatabase struct {
	QueryFunc    func(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRowFunc func(ctx context.Context, sql string, args ...any) pgx.Row
	ExecFunc     func(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	BeginTxFunc  func(ctx context.Context) (storage.Transaction, error)
	PingErr      error
	CloseErr     error
}

FakeDatabase is a configurable double for storage.Database (used at the service/server composition level) and storage.Transaction/storage.DBTX (used to drive sqlc-generated queries directly). Set only the hooks the code under test is expected to call; an unset Query/QueryRow/Exec/BeginTx hook returns a descriptive error so an unexpected call fails loudly instead of touching a nil driver. Ping, Close, Commit, and Rollback default to succeeding, since most callers only care about business-logic reachability, not connection/transaction lifecycle.

func (*FakeDatabase) BeginTx

func (f *FakeDatabase) BeginTx(ctx context.Context) (storage.Transaction, error)

func (*FakeDatabase) Close

func (f *FakeDatabase) Close() error

func (*FakeDatabase) Commit

func (f *FakeDatabase) Commit(context.Context) error

func (*FakeDatabase) Exec

func (f *FakeDatabase) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)

func (*FakeDatabase) Ping

func (*FakeDatabase) Query

func (f *FakeDatabase) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

func (*FakeDatabase) QueryRow

func (f *FakeDatabase) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

func (*FakeDatabase) Rollback

func (f *FakeDatabase) Rollback(context.Context) error

Jump to

Keyboard shortcuts

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