Documentation
¶
Index ¶
- type DBMock
- func (mock *DBMock) CreateTask(ctx context.Context, title string) (*example.Task, error)
- func (mock *DBMock) CreateTaskCalls() []struct{ ... }
- func (mock *DBMock) DeleteTask(ctx context.Context, id int64) error
- func (mock *DBMock) DeleteTaskCalls() []struct{ ... }
- func (mock *DBMock) GenerateError(ctx context.Context) error
- func (mock *DBMock) GenerateErrorCalls() []struct{ ... }
- func (mock *DBMock) ListTasks(ctx context.Context) ([]*example.Task, error)
- func (mock *DBMock) ListTasksCalls() []struct{ ... }
- type ServiceMock
- func (mock *ServiceMock) CreateTask(ctx context.Context, title string) (*example.Task, error)
- func (mock *ServiceMock) CreateTaskCalls() []struct{ ... }
- func (mock *ServiceMock) DeleteTask(ctx context.Context, id int64) error
- func (mock *ServiceMock) DeleteTaskCalls() []struct{ ... }
- func (mock *ServiceMock) GenerateError(ctx context.Context) error
- func (mock *ServiceMock) GenerateErrorCalls() []struct{ ... }
- func (mock *ServiceMock) ListTasks(ctx context.Context) ([]*example.Task, error)
- func (mock *ServiceMock) ListTasksCalls() []struct{ ... }
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 ¶
CreateTask calls CreateTaskFunc.
func (*DBMock) CreateTaskCalls ¶
CreateTaskCalls gets all the calls that were made to CreateTask. Check the length with:
len(mockedDB.CreateTaskCalls())
func (*DBMock) DeleteTask ¶
DeleteTask calls DeleteTaskFunc.
func (*DBMock) DeleteTaskCalls ¶
DeleteTaskCalls gets all the calls that were made to DeleteTask. Check the length with:
len(mockedDB.DeleteTaskCalls())
func (*DBMock) GenerateError ¶
GenerateError calls GenerateErrorFunc.
func (*DBMock) GenerateErrorCalls ¶
GenerateErrorCalls gets all the calls that were made to GenerateError. Check the length with:
len(mockedDB.GenerateErrorCalls())
func (*DBMock) ListTasksCalls ¶
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
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) 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())