Documentation
¶
Index ¶
- Variables
- type ConnMock
- func (c *ConnMock) Begin() (driver.Tx, error)
- func (c *ConnMock) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c *ConnMock) Close() error
- func (c *ConnMock) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (c *ConnMock) Prepare(query string) (driver.Stmt, error)
- func (c *ConnMock) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- type ExpectedCall
- func (call *ExpectedCall) ReturnsEmptyResult() *ExpectedCall
- func (call *ExpectedCall) ReturnsError(err error) *ExpectedCall
- func (call *ExpectedCall) ReturnsNewStmt() *ExpectedCall
- func (call *ExpectedCall) ReturnsNewTx() *ExpectedCall
- func (call *ExpectedCall) ReturnsNoError() *ExpectedCall
- func (call *ExpectedCall) ReturnsResult(result driver.Result) *ExpectedCall
- func (call *ExpectedCall) ReturnsRows(rows driver.Rows) *ExpectedCall
- func (call *ExpectedCall) WithArgs(args ...driver.Value) *ExpectedCall
- func (call *ExpectedCall) WithNamedArgs(args ...driver.NamedValue) *ExpectedCall
- func (call *ExpectedCall) WithQuery(query string) *ExpectedCall
- func (call *ExpectedCall) WithQueryRegex(pattern string) *ExpectedCall
- type FuncType
- type Mock
- func (m *Mock) ExpectBegin() *ExpectedCall
- func (m *Mock) ExpectCommit() *ExpectedCall
- func (m *Mock) ExpectExec() *ExpectedCall
- func (m *Mock) ExpectPrepare() *ExpectedCall
- func (m *Mock) ExpectQuery() *ExpectedCall
- func (m *Mock) ExpectRollback() *ExpectedCall
- func (m *Mock) VerifyExpectations() error
- type MockDriver
- type ResultMock
- type RowsMock
- type StmtMock
- type TransactionMock
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoMoreCalls = errors.New("no more expected calls") ErrBadFunction = errors.New("wrong function called") ErrBadQuery = errors.New("wrong query") ErrArgCountMismatch = errors.New("argument count mismatch") ErrUnexpectedParam = errors.New("unexpected parameter") ErrValueMismatch = errors.New("value mismatch") ErrNilValueMismatch = errors.New("nil/non-nil value mismatch") )
var DriverName = "sqltx_mock2"
Functions ¶
This section is empty.
Types ¶
type ConnMock ¶
type ConnMock struct {
Mock *Mock
}
ConnMock implements the driver.Conn interface.
func (*ConnMock) ExecContext ¶
func (c *ConnMock) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
ExecContext implements driver.ExecerContext
type ExpectedCall ¶
type ExpectedCall struct {
// Mock is a reference back to the parent mock.
Mock *Mock
// Function is the type of the expected function.
Function FuncType
// Args are the expected arguments. (as driver.NamedValue)
Args []driver.NamedValue
// Query for statement preparation, execution, or querying.
Query string
// QueryRegex is used for regex matching of queries.
QueryRegex *regexp.Regexp
// UseRegexForQuery reports whether QueryRegex should be used for matching.
UseRegexForQuery bool
// Possible Return values.
ReturnErr *error
ReturnResult driver.Result
ReturnRows driver.Rows
ReturnTx driver.Tx
ReturnStmt driver.Stmt
}
ExpectedCall represents an expected function call with its arguments and return values
func (*ExpectedCall) ReturnsEmptyResult ¶
func (call *ExpectedCall) ReturnsEmptyResult() *ExpectedCall
func (*ExpectedCall) ReturnsError ¶
func (call *ExpectedCall) ReturnsError(err error) *ExpectedCall
ReturnsError sets the error to return
func (*ExpectedCall) ReturnsNewStmt ¶
func (call *ExpectedCall) ReturnsNewStmt() *ExpectedCall
ReturnsNewStmt creates and sets a new statement to return
func (*ExpectedCall) ReturnsNewTx ¶
func (call *ExpectedCall) ReturnsNewTx() *ExpectedCall
ReturnsNewTx creates and sets a new transaction to return
func (*ExpectedCall) ReturnsNoError ¶
func (call *ExpectedCall) ReturnsNoError() *ExpectedCall
ReturnsNoError sets no error to return.
func (*ExpectedCall) ReturnsResult ¶
func (call *ExpectedCall) ReturnsResult(result driver.Result) *ExpectedCall
ReturnsResult sets the result to return
func (*ExpectedCall) ReturnsRows ¶
func (call *ExpectedCall) ReturnsRows(rows driver.Rows) *ExpectedCall
ReturnsRows sets the rows to return
func (*ExpectedCall) WithArgs ¶
func (call *ExpectedCall) WithArgs(args ...driver.Value) *ExpectedCall
WithArgs sets the expected arguments for the call Convert simple values to NamedValue with ordinal positions
func (*ExpectedCall) WithNamedArgs ¶
func (call *ExpectedCall) WithNamedArgs(args ...driver.NamedValue) *ExpectedCall
WithNamedArgs sets the expected arguments as NamedValue
func (*ExpectedCall) WithQuery ¶
func (call *ExpectedCall) WithQuery(query string) *ExpectedCall
WithQuery sets the expected exact query string for Prepare/Exec/Query calls
func (*ExpectedCall) WithQueryRegex ¶
func (call *ExpectedCall) WithQueryRegex(pattern string) *ExpectedCall
WithQueryRegex sets a regex pattern for matching queries
type Mock ¶
type Mock struct {
// Expected is a slice of expected function calls in order
Expected []*ExpectedCall
// CallIndex is the index of the current call
CallIndex int
// contains filtered or unexported fields
}
Mock contains the mock configuration and expectations.
func NewMockDBTx ¶
NewMockDBTx creates a new sql.DB and sql.Tx with the mock driver
func (*Mock) ExpectBegin ¶
func (m *Mock) ExpectBegin() *ExpectedCall
ExpectBegin adds a new `Begin` call expectation.
func (*Mock) ExpectCommit ¶
func (m *Mock) ExpectCommit() *ExpectedCall
ExpectCommit adds a new `Commit` call expectation.
func (*Mock) ExpectExec ¶
func (m *Mock) ExpectExec() *ExpectedCall
ExpectExec adds a new `Exec` call expectation.
func (*Mock) ExpectPrepare ¶
func (m *Mock) ExpectPrepare() *ExpectedCall
ExpectPrepare adds a new `Prepare` call expectation.
func (*Mock) ExpectQuery ¶
func (m *Mock) ExpectQuery() *ExpectedCall
ExpectQuery adds a new `Query` call expectation.
func (*Mock) ExpectRollback ¶
func (m *Mock) ExpectRollback() *ExpectedCall
ExpectRollback adds a new `Rollback` call expectation.
func (*Mock) VerifyExpectations ¶
VerifyExpectations checks if all expected calls were made
type MockDriver ¶
type MockDriver struct {
// contains filtered or unexported fields
}
MockDriver implements the driver.Driver interface
var Pool *MockDriver
type ResultMock ¶
type ResultMock struct{ LastID, RowsAffectedValue int64 }
ResultMock implements sql.Result for testing
func NewSqlResultMock ¶
func NewSqlResultMock(lastID int64, rowsAffectedValue int64) *ResultMock
func (*ResultMock) LastInsertId ¶
func (m *ResultMock) LastInsertId() (int64, error)
func (*ResultMock) RowsAffected ¶
func (m *ResultMock) RowsAffected() (int64, error)
type RowsMock ¶
type RowsMock struct{}
RowsMock implements the driver.Rows interface
func NewRowsMock ¶
func NewRowsMock() *RowsMock
type StmtMock ¶
type StmtMock struct {
// Mock is the Mock object that created this StmtMock.
Mock *Mock
// contains filtered or unexported fields
}
StmtMock implements the driver.Stmt interface
type TransactionMock ¶
type TransactionMock struct {
Mock *Mock
}
TransactionMock implements the driver.Tx interface.
func (*TransactionMock) Commit ¶
func (tx *TransactionMock) Commit() error
Commit implements the driver.Tx interface.
func (*TransactionMock) Rollback ¶
func (tx *TransactionMock) Rollback() error
Rollback implements the driver.Tx interface.