storetest

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package storetest holds hand-written fakes of the store interfaces for tests: a DB, a Tx and Rows whose answers the test configures and whose calls it reads back, without a mocking library.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoBeginFn = errors.New("store: no BeginFn configured")

ErrNoBeginFn is returned when a FakeDB has no BeginFn configured.

View Source
var ErrNoExecFn = errors.New("store: no ExecFn configured")

ErrNoExecFn is returned when a FakeDB has no ExecFn configured.

View Source
var ErrNoQueryFn = errors.New("store: no QueryFn configured")

ErrNoQueryFn is returned when a FakeDB has no QueryFn configured.

View Source
var ErrScanBeforeNext = errors.New("store: Scan called before Next")

ErrScanBeforeNext is returned when Scan is called before Next.

Functions

This section is empty.

Types

type FakeDB

type FakeDB struct {
	QueryFn func(ctx context.Context, query string, args ...any) (store.Rows, error)
	ExecFn  func(ctx context.Context, query string, args ...any) (store.Result, error)
	BeginFn func(ctx context.Context, opts *store.TxOptions) (store.Tx, error)

	Queries []LoggedQuery
	Execs   []LoggedExec
	TxBegun int
}

FakeDB is a hand-written DB and TxBeginner for tests. Configure the *Fn fields to control responses; calls are recorded for assertion.

func (*FakeDB) BeginTx

func (d *FakeDB) BeginTx(ctx context.Context, opts *store.TxOptions) (store.Tx, error)

func (*FakeDB) ExecContext

func (d *FakeDB) ExecContext(ctx context.Context, query string, args ...any) (store.Result, error)

func (*FakeDB) QueryContext

func (d *FakeDB) QueryContext(ctx context.Context, query string, args ...any) (store.Rows, error)

type FakeRows

type FakeRows struct {
	Cols []string
	Rows [][]any
	// contains filtered or unexported fields
}

FakeRows is a hand-written store.Rows implementation for tests.

func NewFakeRows

func NewFakeRows(cols []string, rows ...[]any) *FakeRows

NewFakeRows builds a FakeRows with the given columns and rows.

func (*FakeRows) Close

func (r *FakeRows) Close() error

func (*FakeRows) Closed

func (r *FakeRows) Closed() bool

Closed reports whether Close was called.

func (*FakeRows) Columns

func (r *FakeRows) Columns() ([]string, error)

func (*FakeRows) Err

func (r *FakeRows) Err() error

func (*FakeRows) Next

func (r *FakeRows) Next() bool

func (*FakeRows) Scan

func (r *FakeRows) Scan(dest ...any) error

func (*FakeRows) SetErr

func (r *FakeRows) SetErr(err error)

SetErr sets the terminal error returned by Err and stops iteration.

type FakeTx

type FakeTx struct {
	Committed  bool
	RolledBack bool
}

FakeTx is a hand-written store.Tx for tests.

func (*FakeTx) Commit

func (t *FakeTx) Commit() error

func (*FakeTx) ExecContext

func (t *FakeTx) ExecContext(_ context.Context, _ string, _ ...any) (store.Result, error)

func (*FakeTx) QueryContext

func (t *FakeTx) QueryContext(_ context.Context, _ string, _ ...any) (store.Rows, error)

QueryContext and ExecContext on FakeTx defer to package-level helpers; tests usually configure a shared FakeDB for tx behavior. For simplicity they return zero values unless overridden via fields.

func (*FakeTx) Rollback

func (t *FakeTx) Rollback() error

type LoggedExec

type LoggedExec struct {
	Query string
	Args  []any
}

LoggedExec records an ExecContext call.

type LoggedQuery

type LoggedQuery struct {
	Query string
	Args  []any
}

LoggedQuery records a QueryContext call.

Jump to

Keyboard shortcuts

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