databasemock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionMock

type ConnectionMock struct {
	QueryFunc  func(ctx context.Context, sql string, args ...any) ([]map[string]any, error)
	CloseFunc  func()
	CloseCount int
	IsClosed   *atomic.Bool
}

func NewConnectionMock

func NewConnectionMock() *ConnectionMock

func (*ConnectionMock) Close

func (c *ConnectionMock) Close()

func (*ConnectionMock) IsConnectionClosed

func (c *ConnectionMock) IsConnectionClosed() bool

IsConnectionClosed returns the status of the connection

func (*ConnectionMock) Query

func (c *ConnectionMock) Query(ctx context.Context, sql string, args ...any) ([]map[string]any, error)

func (*ConnectionMock) WithCloseFunc

func (c *ConnectionMock) WithCloseFunc(fn func()) *ConnectionMock

WithCloseFunc allows setting a custom close function for testing

func (*ConnectionMock) WithQueryFunc

func (c *ConnectionMock) WithQueryFunc(fn func(ctx context.Context, sql string, args ...any) ([]map[string]any, error)) *ConnectionMock

WithQueryFunc allows setting a custom query function for testing

type PoolMock

type PoolMock struct {
	GetConnectionFunc func(params database.PoolParams) (database.Connection, error)
	CloseFunc         func()
	IsClosed          *atomic.Bool
	CloseCount        int
	// contains filtered or unexported fields
}

func NewPoolMock

func NewPoolMock() *PoolMock

func (*PoolMock) Close

func (p *PoolMock) Close()

func (*PoolMock) GetConnection

func (p *PoolMock) GetConnection(params database.PoolParams) (database.Connection, error)

func (*PoolMock) GetConnectionCallCount

func (p *PoolMock) GetConnectionCallCount(params database.PoolParams) int

GetConnectionCallCount returns the number of times GetConnection was called with the given parameters

func (*PoolMock) IsPoolClosed

func (p *PoolMock) IsPoolClosed() bool

IsPoolClosed returns the status of the pool

func (*PoolMock) RegisterConnection

func (p *PoolMock) RegisterConnection(params database.PoolParams, conn database.Connection)

RegisterConnection allows registering a specific connection for specific parameters

func (*PoolMock) WithCloseFunc

func (p *PoolMock) WithCloseFunc(fn func()) *PoolMock

WithCloseFunc allows setting a custom close function for testing

func (*PoolMock) WithGetConnectionFunc

func (p *PoolMock) WithGetConnectionFunc(fn func(params database.PoolParams) (database.Connection, error)) *PoolMock

WithGetConnectionFunc allows setting a custom GetConnection function for testing

Jump to

Keyboard shortcuts

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