Documentation
¶
Overview ¶
Package testutil provides a scriptable database/sql driver for testing sqlkit without a live database.
Index ¶
- type Call
- type Fake
- func (f *Fake) BeginOptions() []driver.TxOptions
- func (f *Fake) Begins() int
- func (f *Fake) Commits() int
- func (f *Fake) DB() *stdsql.DB
- func (f *Fake) Execs() []Call
- func (f *Fake) Queries() []Call
- func (f *Fake) Rollbacks() int
- func (f *Fake) RowCloses() int
- func (f *Fake) RowReads() int
- func (f *Fake) Statements() []string
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
// QueryFunc serves QueryContext calls. Nil means every query returns an
// empty result set.
QueryFunc func(sql string, args []any) (Result, error)
// ExecFunc serves ExecContext calls. Nil means success.
ExecFunc func(sql string, args []any) error
// LastInsertID is reported by the Result of every ExecContext call, so the
// RETURNING-less write-back path (MySQL-style LastInsertId) is testable.
LastInsertID int64
// RowsAffected, when non-nil, is reported by the Result of every ExecContext
// call (otherwise 1), so the optimistic-locking conflict path (zero rows
// affected) is testable.
RowsAffected *int64
// contains filtered or unexported fields
}
Fake is a scriptable in-memory database driver. Set QueryFunc/ExecFunc to control responses; all statements are recorded.
func (*Fake) BeginOptions ¶
BeginOptions returns the transaction options of each begun transaction, in order, so tests can observe the isolation level and read-only flag requested.
func (*Fake) Rollbacks ¶
Rollbacks returns the number of rolled-back transactions, so tests can assert that a failed or panicking unit of work actually rolled its transaction back rather than merely failing to commit.
func (*Fake) RowCloses ¶
RowCloses returns the number of result-set cursors that were closed, so tests can assert a query's rows are always released — on the happy path and when scanning or iteration fails.
func (*Fake) RowReads ¶
RowReads returns the number of rows handed to the caller across all queries, which observes how far result sets were actually read.
func (*Fake) Statements ¶
Statements returns all recorded statements in order of execution.