storagetest

package
v1.24.2 Latest Latest
Warning

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

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

Documentation

Overview

Package storagetest provides in-memory fakes for the storage.DBTX and storage.Transaction interfaces, for unit tests that drive sqlc-generated queries without a real database.

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 Fake

type Fake 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)
}

Fake is a configurable storage.Transaction. Set only the hooks the code under test uses; an unset hook fails the call so unexpected access is caught.

func (Fake) Commit

func (Fake) Commit(context.Context) error

func (Fake) Exec

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

func (Fake) Query

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

func (Fake) QueryRow

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

func (Fake) Rollback

func (Fake) Rollback(context.Context) error

Jump to

Keyboard shortcuts

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