mock

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoExpectation = errors.New("no expectation found")

Functions

func NewResult

func NewResult(command string, rowsAffected int64) pgconn.CommandTag

NewResult creates a pgconn.CommandTag for mocking Exec operation results.

Types

type AcquireAllIdleExpectation

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

func (*AcquireAllIdleExpectation) String

func (e *AcquireAllIdleExpectation) String() string

func (*AcquireAllIdleExpectation) WillReturnConns

func (e *AcquireAllIdleExpectation) WillReturnConns(conns []*pgxpool.Conn)

func (*AcquireAllIdleExpectation) WithArgs

func (e *AcquireAllIdleExpectation) WithArgs(args ...any)

type AcquireExpectation

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

func (*AcquireExpectation) String

func (e *AcquireExpectation) String() string

func (*AcquireExpectation) WillReturnConn

func (e *AcquireExpectation) WillReturnConn(conn *pgxpool.Conn)

func (*AcquireExpectation) WillReturnError

func (e *AcquireExpectation) WillReturnError(err error)

func (*AcquireExpectation) WithArgs

func (e *AcquireExpectation) WithArgs(args ...any)

type AcquireFuncExpectation

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

func (*AcquireFuncExpectation) String

func (e *AcquireFuncExpectation) String() string

func (*AcquireFuncExpectation) WillReturnError

func (e *AcquireFuncExpectation) WillReturnError(err error)

func (*AcquireFuncExpectation) WithArgs

func (e *AcquireFuncExpectation) WithArgs(args ...any)

type BeginExpectation

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

func (*BeginExpectation) String

func (e *BeginExpectation) String() string

func (*BeginExpectation) WillReturnError

func (e *BeginExpectation) WillReturnError(err error)

func (*BeginExpectation) WithArgs

func (e *BeginExpectation) WithArgs(args ...any)

type BeginTxExpectation

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

func (*BeginTxExpectation) String

func (e *BeginTxExpectation) String() string

func (*BeginTxExpectation) WillReturnError

func (e *BeginTxExpectation) WillReturnError(err error)

func (*BeginTxExpectation) WithArgs

func (e *BeginTxExpectation) WithArgs(args ...any)

func (*BeginTxExpectation) WithOptions

func (e *BeginTxExpectation) WithOptions(opts pgx.TxOptions) *BeginTxExpectation

type CloseExpectation

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

func (*CloseExpectation) String

func (e *CloseExpectation) String() string

func (*CloseExpectation) WillReturnError

func (e *CloseExpectation) WillReturnError(err error)

func (*CloseExpectation) WithArgs

func (e *CloseExpectation) WithArgs(args ...any)

type CommitExpectation

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

func (*CommitExpectation) String

func (e *CommitExpectation) String() string

func (*CommitExpectation) WillReturnError

func (e *CommitExpectation) WillReturnError(err error)

func (*CommitExpectation) WithArgs

func (e *CommitExpectation) WithArgs(args ...any)

type CopyFromExpectation

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

func (*CopyFromExpectation) String

func (e *CopyFromExpectation) String() string

func (*CopyFromExpectation) WillReturnError

func (e *CopyFromExpectation) WillReturnError(err error)

func (*CopyFromExpectation) WillReturnResult

func (e *CopyFromExpectation) WillReturnResult(rowsAffected int64)

func (*CopyFromExpectation) WithArgs

func (e *CopyFromExpectation) WithArgs(args ...any)

func (*CopyFromExpectation) WithColumns

func (e *CopyFromExpectation) WithColumns(columns []string) *CopyFromExpectation

type DeallocateAllExpectation

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

func (*DeallocateAllExpectation) String

func (e *DeallocateAllExpectation) String() string

func (*DeallocateAllExpectation) WillReturnError

func (e *DeallocateAllExpectation) WillReturnError(err error)

func (*DeallocateAllExpectation) WithArgs

func (e *DeallocateAllExpectation) WithArgs(args ...any)

type DeallocateExpectation

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

func (*DeallocateExpectation) String

func (e *DeallocateExpectation) String() string

func (*DeallocateExpectation) WillReturnError

func (e *DeallocateExpectation) WillReturnError(err error)

func (*DeallocateExpectation) WithArgs

func (e *DeallocateExpectation) WithArgs(args ...any)

type ExecExpectation

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

func (*ExecExpectation) String

func (e *ExecExpectation) String() string

func (*ExecExpectation) WillReturnError

func (e *ExecExpectation) WillReturnError(err error)

func (*ExecExpectation) WillReturnResult

func (e *ExecExpectation) WillReturnResult(res pgconn.CommandTag)

func (*ExecExpectation) WithArgs

func (e *ExecExpectation) WithArgs(args ...any) *ExecExpectation

type PGXMock

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

PGXMock provides a mock implementation of postgres.PGXConn and pgx.Tx interfaces for testing database interactions without requiring an actual database connection.

func NewPGXMock

func NewPGXMock() *PGXMock

NewPGXMock creates a new mock database connection for testing.

func (*PGXMock) AllExpectationsMet

func (m *PGXMock) AllExpectationsMet() error

AllExpectationsMet verifies that all configured expectations have been fulfilled.

func (*PGXMock) Begin

func (m *PGXMock) Begin(ctx context.Context) (pgx.Tx, error)

func (*PGXMock) BeginTx

func (m *PGXMock) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)

func (*PGXMock) Close

func (m *PGXMock) Close(ctx context.Context) error

func (*PGXMock) Commit

func (m *PGXMock) Commit(ctx context.Context) error

func (*PGXMock) Config

func (m *PGXMock) Config() *pgx.ConnConfig

func (*PGXMock) Conn

func (m *PGXMock) Conn() *pgx.Conn

func (*PGXMock) CopyFrom

func (m *PGXMock) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

func (*PGXMock) Deallocate

func (m *PGXMock) Deallocate(ctx context.Context, name string) error

func (*PGXMock) DeallocateAll

func (m *PGXMock) DeallocateAll(ctx context.Context) error

func (*PGXMock) Exec

func (m *PGXMock) Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error)

func (*PGXMock) ExpectBegin

func (m *PGXMock) ExpectBegin() *BeginExpectation

func (*PGXMock) ExpectBeginTx

func (m *PGXMock) ExpectBeginTx() *BeginTxExpectation

func (*PGXMock) ExpectClose

func (m *PGXMock) ExpectClose() *CloseExpectation

func (*PGXMock) ExpectCommit

func (m *PGXMock) ExpectCommit() *CommitExpectation

func (*PGXMock) ExpectCopyFrom

func (m *PGXMock) ExpectCopyFrom(tableName pgx.Identifier) *CopyFromExpectation

ExpectCopyFrom configures an expectation for bulk copy operations.

func (*PGXMock) ExpectDeallocate

func (m *PGXMock) ExpectDeallocate(name string) *DeallocateExpectation

func (*PGXMock) ExpectDeallocateAll

func (m *PGXMock) ExpectDeallocateAll() *DeallocateAllExpectation

func (*PGXMock) ExpectExec

func (m *PGXMock) ExpectExec(query string) *ExecExpectation

ExpectExec configures an expectation for an Exec operation with the specified query.

func (*PGXMock) ExpectPing

func (m *PGXMock) ExpectPing() *PingExpectation

func (*PGXMock) ExpectPrepare

func (m *PGXMock) ExpectPrepare(name, sql string) *PrepareExpectation

ExpectPrepare configures an expectation for preparing a statement.

func (*PGXMock) ExpectQuery

func (m *PGXMock) ExpectQuery(query string) *QueryExpectation

ExpectQuery configures an expectation for a Query operation with the specified query.

func (*PGXMock) ExpectQueryRow

func (m *PGXMock) ExpectQueryRow(query string) *QueryRowExpectation

ExpectQueryRow configures an expectation for a QueryRow operation with the specified query.

func (*PGXMock) ExpectRollback

func (m *PGXMock) ExpectRollback() *RollbackExpectation

func (*PGXMock) LargeObjects

func (m *PGXMock) LargeObjects() pgx.LargeObjects

func (*PGXMock) PgConn

func (m *PGXMock) PgConn() *pgconn.PgConn

Methods that return nil/defaults for interface compliance

func (*PGXMock) Ping

func (m *PGXMock) Ping(ctx context.Context) error

func (*PGXMock) Prepare

func (m *PGXMock) Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)

func (*PGXMock) Query

func (m *PGXMock) Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)

func (*PGXMock) QueryRow

func (m *PGXMock) QueryRow(ctx context.Context, query string, args ...any) pgx.Row

func (*PGXMock) Rollback

func (m *PGXMock) Rollback(ctx context.Context) error

func (*PGXMock) SendBatch

func (m *PGXMock) SendBatch(ctx context.Context, batch *pgx.Batch) pgx.BatchResults

type PGXPoolMock

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

PGXPoolMock provides a mock implementation of postgres.PGXPool and pgx.Tx interfaces for testing database pool interactions without requiring an actual database connection.

func NewPGXPoolMock

func NewPGXPoolMock() *PGXPoolMock

NewPGXPoolMock creates a new mock database connection pool for testing.

func (*PGXPoolMock) Acquire

func (m *PGXPoolMock) Acquire(ctx context.Context) (*pgxpool.Conn, error)

func (*PGXPoolMock) AcquireAllIdle

func (m *PGXPoolMock) AcquireAllIdle(ctx context.Context) []*pgxpool.Conn

func (*PGXPoolMock) AcquireFunc

func (m *PGXPoolMock) AcquireFunc(ctx context.Context, fn func(*pgxpool.Conn) error) error

AcquireFunc executes fn with a nil connection for mock purposes.

func (*PGXPoolMock) AllExpectationsMet

func (m *PGXPoolMock) AllExpectationsMet() error

AllExpectationsMet verifies that all configured expectations have been fulfilled.

func (*PGXPoolMock) Begin

func (m *PGXPoolMock) Begin(ctx context.Context) (pgx.Tx, error)

func (*PGXPoolMock) BeginTx

func (m *PGXPoolMock) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)

func (*PGXPoolMock) Close

func (m *PGXPoolMock) Close()

func (*PGXPoolMock) Commit

func (m *PGXPoolMock) Commit(ctx context.Context) error

func (*PGXPoolMock) Config

func (m *PGXPoolMock) Config() *pgxpool.Config

func (*PGXPoolMock) Conn

func (m *PGXPoolMock) Conn() *pgx.Conn

func (*PGXPoolMock) CopyFrom

func (m *PGXPoolMock) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

func (*PGXPoolMock) Exec

func (m *PGXPoolMock) Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error)

func (*PGXPoolMock) ExpectAcquire

func (m *PGXPoolMock) ExpectAcquire() *AcquireExpectation

ExpectAcquire configures an expectation for acquiring a connection from the pool.

func (*PGXPoolMock) ExpectAcquireAllIdle

func (m *PGXPoolMock) ExpectAcquireAllIdle() *AcquireAllIdleExpectation

ExpectAcquireAllIdle configures an expectation for acquiring all idle connections.

func (*PGXPoolMock) ExpectAcquireFunc

func (m *PGXPoolMock) ExpectAcquireFunc() *AcquireFuncExpectation

ExpectAcquireFunc configures an expectation for AcquireFunc operations.

func (*PGXPoolMock) ExpectBegin

func (m *PGXPoolMock) ExpectBegin() *BeginExpectation

func (*PGXPoolMock) ExpectBeginTx

func (m *PGXPoolMock) ExpectBeginTx() *BeginTxExpectation

func (*PGXPoolMock) ExpectClose

func (m *PGXPoolMock) ExpectClose() *CloseExpectation

func (*PGXPoolMock) ExpectCommit

func (m *PGXPoolMock) ExpectCommit() *CommitExpectation

func (*PGXPoolMock) ExpectCopyFrom

func (m *PGXPoolMock) ExpectCopyFrom(tableName pgx.Identifier) *PoolCopyFromExpectation

ExpectCopyFrom configures an expectation for bulk copy operations.

func (*PGXPoolMock) ExpectExec

func (m *PGXPoolMock) ExpectExec(query string) *ExecExpectation

ExpectExec configures an expectation for an Exec operation with the specified query.

func (*PGXPoolMock) ExpectPing

func (m *PGXPoolMock) ExpectPing() *PingExpectation

func (*PGXPoolMock) ExpectPrepare

func (m *PGXPoolMock) ExpectPrepare(name, sql string) *PoolPrepareExpectation

ExpectPrepare configures an expectation for preparing a statement.

func (*PGXPoolMock) ExpectQuery

func (m *PGXPoolMock) ExpectQuery(query string) *QueryExpectation

ExpectQuery configures an expectation for a Query operation with the specified query.

func (*PGXPoolMock) ExpectQueryRow

func (m *PGXPoolMock) ExpectQueryRow(query string) *QueryRowExpectation

ExpectQueryRow configures an expectation for a QueryRow operation with the specified query.

func (*PGXPoolMock) ExpectRollback

func (m *PGXPoolMock) ExpectRollback() *RollbackExpectation

func (*PGXPoolMock) LargeObjects

func (m *PGXPoolMock) LargeObjects() pgx.LargeObjects

func (*PGXPoolMock) Ping

func (m *PGXPoolMock) Ping(ctx context.Context) error

func (*PGXPoolMock) Prepare

func (m *PGXPoolMock) Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)

func (*PGXPoolMock) Query

func (m *PGXPoolMock) Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)

func (*PGXPoolMock) QueryRow

func (m *PGXPoolMock) QueryRow(ctx context.Context, query string, args ...any) pgx.Row

func (*PGXPoolMock) Reset

func (m *PGXPoolMock) Reset()

Methods that return nil/defaults for interface compliance

func (*PGXPoolMock) Rollback

func (m *PGXPoolMock) Rollback(ctx context.Context) error

func (*PGXPoolMock) SendBatch

func (m *PGXPoolMock) SendBatch(ctx context.Context, batch *pgx.Batch) pgx.BatchResults

func (*PGXPoolMock) Stat

func (m *PGXPoolMock) Stat() *pgxpool.Stat

type PingExpectation

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

func (*PingExpectation) String

func (e *PingExpectation) String() string

func (*PingExpectation) WillReturnError

func (e *PingExpectation) WillReturnError(err error)

func (*PingExpectation) WithArgs

func (e *PingExpectation) WithArgs(args ...any)

type PoolCopyFromExpectation

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

func (*PoolCopyFromExpectation) String

func (e *PoolCopyFromExpectation) String() string

func (*PoolCopyFromExpectation) WillReturnError

func (e *PoolCopyFromExpectation) WillReturnError(err error)

func (*PoolCopyFromExpectation) WillReturnResult

func (e *PoolCopyFromExpectation) WillReturnResult(rowsAffected int64)

func (*PoolCopyFromExpectation) WithArgs

func (e *PoolCopyFromExpectation) WithArgs(args ...any)

func (*PoolCopyFromExpectation) WithColumns

func (e *PoolCopyFromExpectation) WithColumns(columns []string) *PoolCopyFromExpectation

type PoolPrepareExpectation

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

func (*PoolPrepareExpectation) String

func (e *PoolPrepareExpectation) String() string

func (*PoolPrepareExpectation) WillReturnError

func (e *PoolPrepareExpectation) WillReturnError(err error)

func (*PoolPrepareExpectation) WillReturnResult

func (e *PoolPrepareExpectation) WillReturnResult(desc *pgconn.StatementDescription)

func (*PoolPrepareExpectation) WithArgs

func (e *PoolPrepareExpectation) WithArgs(args ...any)

func (*PoolPrepareExpectation) WithName

type PrepareExpectation

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

func (*PrepareExpectation) String

func (e *PrepareExpectation) String() string

func (*PrepareExpectation) WillReturnError

func (e *PrepareExpectation) WillReturnError(err error)

func (*PrepareExpectation) WillReturnResult

func (e *PrepareExpectation) WillReturnResult(desc *pgconn.StatementDescription)

func (*PrepareExpectation) WithArgs

func (e *PrepareExpectation) WithArgs(args ...any)

func (*PrepareExpectation) WithName

func (e *PrepareExpectation) WithName(name string) *PrepareExpectation

type QueryExpectation

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

func (*QueryExpectation) String

func (e *QueryExpectation) String() string

func (*QueryExpectation) WillReturnError

func (e *QueryExpectation) WillReturnError(err error)

func (*QueryExpectation) WillReturnRows

func (e *QueryExpectation) WillReturnRows(rows pgx.Rows)

func (*QueryExpectation) WithArgs

func (e *QueryExpectation) WithArgs(args ...any) *QueryExpectation

type QueryRowExpectation

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

func (*QueryRowExpectation) String

func (e *QueryRowExpectation) String() string

func (*QueryRowExpectation) WillReturnRow

func (e *QueryRowExpectation) WillReturnRow(row pgx.Row)

func (*QueryRowExpectation) WithArgs

func (e *QueryRowExpectation) WithArgs(args ...any) *QueryRowExpectation

type RollbackExpectation

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

func (*RollbackExpectation) String

func (e *RollbackExpectation) String() string

func (*RollbackExpectation) WillReturnError

func (e *RollbackExpectation) WillReturnError(err error)

func (*RollbackExpectation) WithArgs

func (e *RollbackExpectation) WithArgs(args ...any)

type Row

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

Row provides a mock implementation of pgx.Row for testing QueryRow operations.

func NewRow

func NewRow(row ...any) *Row

func (*Row) Scan

func (r *Row) Scan(dest ...any) error

Scan copies row values into destination pointers using reflection.

func (*Row) WillReturnError

func (r *Row) WillReturnError(err error) *Row

type Rows

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

Rows provides a mock implementation of pgx.Rows for testing Query operations. Supports adding rows and controlling iteration behavior.

func NewRows

func NewRows(columns []string) *Rows

func (*Rows) AddRow

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

AddRow appends a data row with values matching the column count.

func (*Rows) Close

func (r *Rows) Close()

func (*Rows) CommandTag

func (r *Rows) CommandTag() pgconn.CommandTag

func (*Rows) Conn

func (r *Rows) Conn() *pgx.Conn

func (*Rows) Err

func (r *Rows) Err() error

func (*Rows) FieldDescriptions

func (r *Rows) FieldDescriptions() []pgconn.FieldDescription

func (*Rows) GetRowsForTesting

func (r *Rows) GetRowsForTesting() [][]any

GetRowsForTesting exposes internal row data for test verification.

func (*Rows) Next

func (r *Rows) Next() bool

func (*Rows) RawValues

func (r *Rows) RawValues() [][]byte

RawValues returns current row values as byte slices for compatibility.

func (*Rows) Scan

func (r *Rows) Scan(dest ...any) error

Scan copies current row values into destination pointers using reflection.

func (*Rows) Values

func (r *Rows) Values() ([]any, error)

Jump to

Keyboard shortcuts

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