Add an additional line of code per interface to the generated mock file, which allows the go compiler to statically check if the mock implements the mocked interface.
78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
// Code generated by moq; DO NOT EDIT.
|
|
// github.com/matryer/moq
|
|
|
|
package user
|
|
|
|
import (
|
|
"github.com/matryer/somerepo"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
lockServiceMockDoSomething sync.RWMutex
|
|
)
|
|
|
|
// Ensure, that ServiceMock does implement Service.
|
|
// If this is not the case, regenerate this file with moq.
|
|
var _ Service = &ServiceMock{}
|
|
|
|
// ServiceMock is a mock implementation of Service.
|
|
//
|
|
// func TestSomethingThatUsesService(t *testing.T) {
|
|
//
|
|
// // make and configure a mocked Service
|
|
// mockedService := &ServiceMock{
|
|
// DoSomethingFunc: func(in1 somerepo.SomeType) error {
|
|
// panic("TODO: mock out the DoSomething method")
|
|
// },
|
|
// }
|
|
//
|
|
// // TODO: use mockedService in code that requires Service
|
|
// // and then make assertions.
|
|
//
|
|
// }
|
|
type ServiceMock struct {
|
|
// DoSomethingFunc mocks the DoSomething method.
|
|
DoSomethingFunc func(in1 somerepo.SomeType) error
|
|
|
|
// calls tracks calls to the methods.
|
|
calls struct {
|
|
// DoSomething holds details about calls to the DoSomething method.
|
|
DoSomething []struct {
|
|
// In1 is the in1 argument value.
|
|
In1 somerepo.SomeType
|
|
}
|
|
}
|
|
}
|
|
|
|
// DoSomething calls DoSomethingFunc.
|
|
func (mock *ServiceMock) DoSomething(in1 somerepo.SomeType) error {
|
|
if mock.DoSomethingFunc == nil {
|
|
panic("ServiceMock.DoSomethingFunc: method is nil but Service.DoSomething was just called")
|
|
}
|
|
callInfo := struct {
|
|
In1 somerepo.SomeType
|
|
}{
|
|
In1: in1,
|
|
}
|
|
lockServiceMockDoSomething.Lock()
|
|
mock.calls.DoSomething = append(mock.calls.DoSomething, callInfo)
|
|
lockServiceMockDoSomething.Unlock()
|
|
return mock.DoSomethingFunc(in1)
|
|
}
|
|
|
|
// DoSomethingCalls gets all the calls that were made to DoSomething.
|
|
// Check the length with:
|
|
// len(mockedService.DoSomethingCalls())
|
|
func (mock *ServiceMock) DoSomethingCalls() []struct {
|
|
In1 somerepo.SomeType
|
|
} {
|
|
var calls []struct {
|
|
In1 somerepo.SomeType
|
|
}
|
|
lockServiceMockDoSomething.RLock()
|
|
calls = mock.calls.DoSomething
|
|
lockServiceMockDoSomething.RUnlock()
|
|
return calls
|
|
}
|