mock

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBMock

type DBMock struct {
	// CreateTaskFunc mocks the CreateTask method.
	CreateTaskFunc func(ctx context.Context, title string) (*example.Task, error)

	// DeleteTaskFunc mocks the DeleteTask method.
	DeleteTaskFunc func(ctx context.Context, id int64) error

	// GenerateErrorFunc mocks the GenerateError method.
	GenerateErrorFunc func(ctx context.Context) error

	// ListTasksFunc mocks the ListTasks method.
	ListTasksFunc func(ctx context.Context) ([]*example.Task, error)
	// contains filtered or unexported fields
}

DBMock is a mock implementation of example.DB.

func TestSomethingThatUsesDB(t *testing.T) {

	// make and configure a mocked example.DB
	mockedDB := &DBMock{
		CreateTaskFunc: func(ctx context.Context, title string) (*example.Task, error) {
			panic("mock out the CreateTask method")
		},
		DeleteTaskFunc: func(ctx context.Context, id int64) error {
			panic("mock out the DeleteTask method")
		},
		GenerateErrorFunc: func(ctx context.Context) error {
			panic("mock out the GenerateError method")
		},
		ListTasksFunc: func(ctx context.Context) ([]*example.Task, error) {
			panic("mock out the ListTasks method")
		},
	}

	// use mockedDB in code that requires example.DB
	// and then make assertions.

}

func (*DBMock) CreateTask

func (mock *DBMock) CreateTask(ctx context.Context, title string) (*example.Task, error)

CreateTask calls CreateTaskFunc.

func (*DBMock) CreateTaskCalls

func (mock *DBMock) CreateTaskCalls() []struct {
	Ctx   context.Context
	Title string
}

CreateTaskCalls gets all the calls that were made to CreateTask. Check the length with:

len(mockedDB.CreateTaskCalls())

func (*DBMock) DeleteTask

func (mock *DBMock) DeleteTask(ctx context.Context, id int64) error

DeleteTask calls DeleteTaskFunc.

func (*DBMock) DeleteTaskCalls

func (mock *DBMock) DeleteTaskCalls() []struct {
	Ctx context.Context
	ID  int64
}

DeleteTaskCalls gets all the calls that were made to DeleteTask. Check the length with:

len(mockedDB.DeleteTaskCalls())

func (*DBMock) GenerateError

func (mock *DBMock) GenerateError(ctx context.Context) error

GenerateError calls GenerateErrorFunc.

func (*DBMock) GenerateErrorCalls

func (mock *DBMock) GenerateErrorCalls() []struct {
	Ctx context.Context
}

GenerateErrorCalls gets all the calls that were made to GenerateError. Check the length with:

len(mockedDB.GenerateErrorCalls())

func (*DBMock) ListTasks

func (mock *DBMock) ListTasks(ctx context.Context) ([]*example.Task, error)

ListTasks calls ListTasksFunc.

func (*DBMock) ListTasksCalls

func (mock *DBMock) ListTasksCalls() []struct {
	Ctx context.Context
}

ListTasksCalls gets all the calls that were made to ListTasks. Check the length with:

len(mockedDB.ListTasksCalls())

type ServiceMock added in v0.3.0

type ServiceMock struct {
	// CreateTaskFunc mocks the CreateTask method.
	CreateTaskFunc func(ctx context.Context, title string) (*example.Task, error)

	// DeleteTaskFunc mocks the DeleteTask method.
	DeleteTaskFunc func(ctx context.Context, id int64) error

	// GenerateErrorFunc mocks the GenerateError method.
	GenerateErrorFunc func(ctx context.Context) error

	// ListTasksFunc mocks the ListTasks method.
	ListTasksFunc func(ctx context.Context) ([]*example.Task, error)
	// contains filtered or unexported fields
}

ServiceMock is a mock implementation of example.Service.

func TestSomethingThatUsesService(t *testing.T) {

	// make and configure a mocked example.Service
	mockedService := &ServiceMock{
		CreateTaskFunc: func(ctx context.Context, title string) (*example.Task, error) {
			panic("mock out the CreateTask method")
		},
		DeleteTaskFunc: func(ctx context.Context, id int64) error {
			panic("mock out the DeleteTask method")
		},
		GenerateErrorFunc: func(ctx context.Context) error {
			panic("mock out the GenerateError method")
		},
		ListTasksFunc: func(ctx context.Context) ([]*example.Task, error) {
			panic("mock out the ListTasks method")
		},
	}

	// use mockedService in code that requires example.Service
	// and then make assertions.

}

func (*ServiceMock) CreateTask added in v0.3.0

func (mock *ServiceMock) CreateTask(ctx context.Context, title string) (*example.Task, error)

CreateTask calls CreateTaskFunc.

func (*ServiceMock) CreateTaskCalls added in v0.3.0

func (mock *ServiceMock) CreateTaskCalls() []struct {
	Ctx   context.Context
	Title string
}

CreateTaskCalls gets all the calls that were made to CreateTask. Check the length with:

len(mockedService.CreateTaskCalls())

func (*ServiceMock) DeleteTask added in v0.3.0

func (mock *ServiceMock) DeleteTask(ctx context.Context, id int64) error

DeleteTask calls DeleteTaskFunc.

func (*ServiceMock) DeleteTaskCalls added in v0.3.0

func (mock *ServiceMock) DeleteTaskCalls() []struct {
	Ctx context.Context
	ID  int64
}

DeleteTaskCalls gets all the calls that were made to DeleteTask. Check the length with:

len(mockedService.DeleteTaskCalls())

func (*ServiceMock) GenerateError added in v0.3.0

func (mock *ServiceMock) GenerateError(ctx context.Context) error

GenerateError calls GenerateErrorFunc.

func (*ServiceMock) GenerateErrorCalls added in v0.3.0

func (mock *ServiceMock) GenerateErrorCalls() []struct {
	Ctx context.Context
}

GenerateErrorCalls gets all the calls that were made to GenerateError. Check the length with:

len(mockedService.GenerateErrorCalls())

func (*ServiceMock) ListTasks added in v0.3.0

func (mock *ServiceMock) ListTasks(ctx context.Context) ([]*example.Task, error)

ListTasks calls ListTasksFunc.

func (*ServiceMock) ListTasksCalls added in v0.3.0

func (mock *ServiceMock) ListTasksCalls() []struct {
	Ctx context.Context
}

ListTasksCalls gets all the calls that were made to ListTasks. Check the length with:

len(mockedService.ListTasksCalls())

Jump to

Keyboard shortcuts

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