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 ¶
var ErrNoBeginFn = errors.New("store: no BeginFn configured")
ErrNoBeginFn is returned when a FakeDB has no BeginFn configured.
var ErrNoExecFn = errors.New("store: no ExecFn configured")
ErrNoExecFn is returned when a FakeDB has no ExecFn configured.
var ErrNoQueryFn = errors.New("store: no QueryFn configured")
ErrNoQueryFn is returned when a FakeDB has no QueryFn configured.
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) ExecContext ¶
type FakeRows ¶
FakeRows is a hand-written store.Rows implementation for tests.
func NewFakeRows ¶
NewFakeRows builds a FakeRows with the given columns and rows.
type FakeTx ¶
FakeTx is a hand-written store.Tx for tests.
func (*FakeTx) ExecContext ¶
func (*FakeTx) QueryContext ¶
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.
type LoggedExec ¶
LoggedExec records an ExecContext call.
type LoggedQuery ¶
LoggedQuery records a QueryContext call.