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 ¶
- func Row(fn func(dest ...any) error) pgx.Row
- func Rows(scans ...func(dest ...any) error) pgx.Rows
- type FakeDatabase
- func (f *FakeDatabase) BeginTx(ctx context.Context) (storage.Transaction, error)
- func (f *FakeDatabase) Close() error
- func (f *FakeDatabase) Commit(context.Context) error
- func (f *FakeDatabase) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
- func (f *FakeDatabase) Ping(context.Context, time.Duration) error
- func (f *FakeDatabase) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
- func (f *FakeDatabase) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- func (f *FakeDatabase) Rollback(context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) Exec ¶
func (f *FakeDatabase) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)