mock

package
v0.0.0-...-ace544b Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package mock provides a mock sql driver for tests. Register the driver with the database/sql package:

sql.Register("mock-driver-name", &mock.Driver{})

Index

Constants

This section is empty.

Variables

View Source
var (
	// AnyArg represents an argument whose value might be dynamic (randomized).
	AnyArg = &struct{ name string }{"any argument"}
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	PrepareFunc func(query string) (driver.Stmt, error)
	BeginFunc   func() (driver.Tx, error)
}

Conn implements the sql/driver.Conn interface.

func NewQueryConn

func NewQueryConn(query Query, results [][]interface{}) Conn

func NewTransactionConn

func NewTransactionConn(commands ...Query) Conn

func (Conn) Begin

func (m Conn) Begin() (driver.Tx, error)

func (Conn) Close

func (m Conn) Close() error

func (Conn) Prepare

func (m Conn) Prepare(query string) (driver.Stmt, error)

type Driver

type Driver struct {
	OpenFunc func(name string) (Conn, error)
}

Driver implements the sql/driver.Conn interface.

func (*Driver) Open

func (m *Driver) Open(name string) (driver.Conn, error)

type Query

type Query struct {
	Name         string
	Args         []interface{}
	RowsAffected int64
}

Query simplifies sending arguments/constraints to custom connections.

func NewAnyQuery

func NewAnyQuery(rowsAffected int64) *Query

NewAnyQuery creates a query that allows any name/args.

type Result

type Result struct {
	RowsAffectedFunc func() (int64, error)
}

Result implements the sql/driver.Result interface.

func (Result) LastInsertId

func (m Result) LastInsertId() (int64, error)

func (Result) RowsAffected

func (m Result) RowsAffected() (int64, error)

type Rows

type Rows struct {
	ColumnsFunc func() []string
	CloseFunc   func() error
	NextFunc    func(dest []driver.Value) error
}

Rows implements the sql/driver.Rows interface.

func (Rows) Close

func (m Rows) Close() error

func (Rows) Columns

func (m Rows) Columns() []string

func (Rows) Next

func (m Rows) Next(dest []driver.Value) error

type Stmt

type Stmt struct {
	CloseFunc    func() error
	NumInputFunc func() int
	ExecFunc     func(args []driver.Value) (driver.Result, error)
	QueryFunc    func(args []driver.Value) (driver.Rows, error)
}

Stmt implements the sql/driver.Stmt interface.

func (Stmt) Close

func (m Stmt) Close() error

func (Stmt) Exec

func (m Stmt) Exec(args []driver.Value) (driver.Result, error)

func (Stmt) NumInput

func (m Stmt) NumInput() int

func (Stmt) Query

func (m Stmt) Query(args []driver.Value) (driver.Rows, error)

type Tx

type Tx struct {
	CommitFunc   func() error
	RollbackFunc func() error
}

Tx implements the sql/driver/Tx interface.

func (Tx) Commit

func (m Tx) Commit() error

func (Tx) Rollback

func (m Tx) Rollback() error

Jump to

Keyboard shortcuts

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