queriestest

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package queriestest implements utilities for testing SQL queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(t *testing.T, d Driver) *sql.DB

NewDB creates a test sql.DB backed by the given Driver.

func NewResult

func NewResult(lastInsertId, rowsAffected int64) driver.Result

NewResult creates a test driver.Result from the given values.

Types

type Driver

type Driver struct {
	// ExecContext is a test implementation of [driver.ExecerContext].
	// If the code being tested uses [sql.Result],
	// ExecContext should return a [driver.Result] created with [NewResult].
	// Optional.
	ExecContext func(t *testing.T, query string, args []any) (driver.Result, error)

	// QueryContext is a test implementation of [driver.QueryerContext].
	// If the code being tested uses [sql.Rows],
	// QueryContext should return [Rows] created with [NewRows].
	// Optional.
	QueryContext func(t *testing.T, query string, args []any) (driver.Rows, error)
}

Driver is a convenience helper to easily create an implementation of driver.Driver for use in tests.

type Rows

type Rows struct {
	// contains filtered or unexported fields
}

Rows is a test implementation of driver.Rows.

func NewRows

func NewRows(columns ...string) *Rows

NewRows creates Rows from the given columns.

func (*Rows) Add

func (r *Rows) Add(values ...any) *Rows

Add adds another row to the Rows.

func (*Rows) Close

func (r *Rows) Close() error

Close implements driver.Rows.

func (*Rows) Columns

func (r *Rows) Columns() []string

Columns implements driver.Rows.

func (*Rows) Next

func (r *Rows) Next(values []driver.Value) error

Next implements driver.Rows.

Jump to

Keyboard shortcuts

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