mockdatabase

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: AGPL-3.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mockdatabase provides moq-generated mocks for the database package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientMock

type ClientMock struct {
	// CloseFunc mocks the Close method.
	CloseFunc func() error

	// CurrentTimeFunc mocks the CurrentTime method.
	CurrentTimeFunc func() time.Time

	// ReadDBFunc mocks the ReadDB method.
	ReadDBFunc func() *sql.DB

	// RollbackTransactionFunc mocks the RollbackTransaction method.
	RollbackTransactionFunc func(ctx context.Context, tx database.SQLQueryExecutorAndTransactionManager)

	// WriteDBFunc mocks the WriteDB method.
	WriteDBFunc func() *sql.DB
	// contains filtered or unexported fields
}

ClientMock is a mock implementation of database.Client.

func TestSomethingThatUsesClient(t *testing.T) {

	// make and configure a mocked database.Client
	mockedClient := &ClientMock{
		CloseFunc: func() error {
			panic("mock out the Close method")
		},
		CurrentTimeFunc: func() time.Time {
			panic("mock out the CurrentTime method")
		},
		ReadDBFunc: func() *sql.DB {
			panic("mock out the ReadDB method")
		},
		RollbackTransactionFunc: func(ctx context.Context, tx database.SQLQueryExecutorAndTransactionManager)  {
			panic("mock out the RollbackTransaction method")
		},
		WriteDBFunc: func() *sql.DB {
			panic("mock out the WriteDB method")
		},
	}

	// use mockedClient in code that requires database.Client
	// and then make assertions.

}

func (*ClientMock) Close

func (mock *ClientMock) Close() error

Close calls CloseFunc.

func (*ClientMock) CloseCalls

func (mock *ClientMock) CloseCalls() []struct {
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedClient.CloseCalls())

func (*ClientMock) CurrentTime

func (mock *ClientMock) CurrentTime() time.Time

CurrentTime calls CurrentTimeFunc.

func (*ClientMock) CurrentTimeCalls

func (mock *ClientMock) CurrentTimeCalls() []struct {
}

CurrentTimeCalls gets all the calls that were made to CurrentTime. Check the length with:

len(mockedClient.CurrentTimeCalls())

func (*ClientMock) ReadDB

func (mock *ClientMock) ReadDB() *sql.DB

ReadDB calls ReadDBFunc.

func (*ClientMock) ReadDBCalls

func (mock *ClientMock) ReadDBCalls() []struct {
}

ReadDBCalls gets all the calls that were made to ReadDB. Check the length with:

len(mockedClient.ReadDBCalls())

func (*ClientMock) RollbackTransaction

func (mock *ClientMock) RollbackTransaction(ctx context.Context, tx database.SQLQueryExecutorAndTransactionManager)

RollbackTransaction calls RollbackTransactionFunc.

func (*ClientMock) RollbackTransactionCalls

func (mock *ClientMock) RollbackTransactionCalls() []struct {
	Ctx context.Context
	Tx  database.SQLQueryExecutorAndTransactionManager
}

RollbackTransactionCalls gets all the calls that were made to RollbackTransaction. Check the length with:

len(mockedClient.RollbackTransactionCalls())

func (*ClientMock) WriteDB

func (mock *ClientMock) WriteDB() *sql.DB

WriteDB calls WriteDBFunc.

func (*ClientMock) WriteDBCalls

func (mock *ClientMock) WriteDBCalls() []struct {
}

WriteDBCalls gets all the calls that were made to WriteDB. Check the length with:

len(mockedClient.WriteDBCalls())

type ResultIteratorMock

type ResultIteratorMock struct {
	// CloseFunc mocks the Close method.
	CloseFunc func() error

	// ErrFunc mocks the Err method.
	ErrFunc func() error

	// NextFunc mocks the Next method.
	NextFunc func() bool

	// ScanFunc mocks the Scan method.
	ScanFunc func(dest ...any) error
	// contains filtered or unexported fields
}

ResultIteratorMock is a mock implementation of database.ResultIterator.

func TestSomethingThatUsesResultIterator(t *testing.T) {

	// make and configure a mocked database.ResultIterator
	mockedResultIterator := &ResultIteratorMock{
		CloseFunc: func() error {
			panic("mock out the Close method")
		},
		ErrFunc: func() error {
			panic("mock out the Err method")
		},
		NextFunc: func() bool {
			panic("mock out the Next method")
		},
		ScanFunc: func(dest ...any) error {
			panic("mock out the Scan method")
		},
	}

	// use mockedResultIterator in code that requires database.ResultIterator
	// and then make assertions.

}

func (*ResultIteratorMock) Close

func (mock *ResultIteratorMock) Close() error

Close calls CloseFunc.

func (*ResultIteratorMock) CloseCalls

func (mock *ResultIteratorMock) CloseCalls() []struct {
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedResultIterator.CloseCalls())

func (*ResultIteratorMock) Err

func (mock *ResultIteratorMock) Err() error

Err calls ErrFunc.

func (*ResultIteratorMock) ErrCalls

func (mock *ResultIteratorMock) ErrCalls() []struct {
}

ErrCalls gets all the calls that were made to Err. Check the length with:

len(mockedResultIterator.ErrCalls())

func (*ResultIteratorMock) Next

func (mock *ResultIteratorMock) Next() bool

Next calls NextFunc.

func (*ResultIteratorMock) NextCalls

func (mock *ResultIteratorMock) NextCalls() []struct {
}

NextCalls gets all the calls that were made to Next. Check the length with:

len(mockedResultIterator.NextCalls())

func (*ResultIteratorMock) Scan

func (mock *ResultIteratorMock) Scan(dest ...any) error

Scan calls ScanFunc.

func (*ResultIteratorMock) ScanCalls

func (mock *ResultIteratorMock) ScanCalls() []struct {
	Dest []any
}

ScanCalls gets all the calls that were made to Scan. Check the length with:

len(mockedResultIterator.ScanCalls())

type SQLQueryExecutorMock

type SQLQueryExecutorMock struct {
	// ExecContextFunc mocks the ExecContext method.
	ExecContextFunc func(ctx context.Context, query string, args ...any) (sql.Result, error)

	// PrepareContextFunc mocks the PrepareContext method.
	PrepareContextFunc func(contextMoqParam context.Context, s string) (*sql.Stmt, error)

	// QueryContextFunc mocks the QueryContext method.
	QueryContextFunc func(ctx context.Context, query string, args ...any) (*sql.Rows, error)

	// QueryRowContextFunc mocks the QueryRowContext method.
	QueryRowContextFunc func(ctx context.Context, query string, args ...any) *sql.Row
	// contains filtered or unexported fields
}

SQLQueryExecutorMock is a mock implementation of database.SQLQueryExecutor.

func TestSomethingThatUsesSQLQueryExecutor(t *testing.T) {

	// make and configure a mocked database.SQLQueryExecutor
	mockedSQLQueryExecutor := &SQLQueryExecutorMock{
		ExecContextFunc: func(ctx context.Context, query string, args ...any) (sql.Result, error) {
			panic("mock out the ExecContext method")
		},
		PrepareContextFunc: func(contextMoqParam context.Context, s string) (*sql.Stmt, error) {
			panic("mock out the PrepareContext method")
		},
		QueryContextFunc: func(ctx context.Context, query string, args ...any) (*sql.Rows, error) {
			panic("mock out the QueryContext method")
		},
		QueryRowContextFunc: func(ctx context.Context, query string, args ...any) *sql.Row {
			panic("mock out the QueryRowContext method")
		},
	}

	// use mockedSQLQueryExecutor in code that requires database.SQLQueryExecutor
	// and then make assertions.

}

func (*SQLQueryExecutorMock) ExecContext

func (mock *SQLQueryExecutorMock) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext calls ExecContextFunc.

func (*SQLQueryExecutorMock) ExecContextCalls

func (mock *SQLQueryExecutorMock) ExecContextCalls() []struct {
	Ctx   context.Context
	Query string
	Args  []any
}

ExecContextCalls gets all the calls that were made to ExecContext. Check the length with:

len(mockedSQLQueryExecutor.ExecContextCalls())

func (*SQLQueryExecutorMock) PrepareContext

func (mock *SQLQueryExecutorMock) PrepareContext(contextMoqParam context.Context, s string) (*sql.Stmt, error)

PrepareContext calls PrepareContextFunc.

func (*SQLQueryExecutorMock) PrepareContextCalls

func (mock *SQLQueryExecutorMock) PrepareContextCalls() []struct {
	ContextMoqParam context.Context
	S               string
}

PrepareContextCalls gets all the calls that were made to PrepareContext. Check the length with:

len(mockedSQLQueryExecutor.PrepareContextCalls())

func (*SQLQueryExecutorMock) QueryContext

func (mock *SQLQueryExecutorMock) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext calls QueryContextFunc.

func (*SQLQueryExecutorMock) QueryContextCalls

func (mock *SQLQueryExecutorMock) QueryContextCalls() []struct {
	Ctx   context.Context
	Query string
	Args  []any
}

QueryContextCalls gets all the calls that were made to QueryContext. Check the length with:

len(mockedSQLQueryExecutor.QueryContextCalls())

func (*SQLQueryExecutorMock) QueryRowContext

func (mock *SQLQueryExecutorMock) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext calls QueryRowContextFunc.

func (*SQLQueryExecutorMock) QueryRowContextCalls

func (mock *SQLQueryExecutorMock) QueryRowContextCalls() []struct {
	Ctx   context.Context
	Query string
	Args  []any
}

QueryRowContextCalls gets all the calls that were made to QueryRowContext. Check the length with:

len(mockedSQLQueryExecutor.QueryRowContextCalls())

Jump to

Keyboard shortcuts

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