diff --git a/example/mockpersonstore_test.go b/example/mockpersonstore_test.go index 8be997d..a0880b5 100755 --- a/example/mockpersonstore_test.go +++ b/example/mockpersonstore_test.go @@ -62,7 +62,7 @@ type PersonStoreMock struct { // Create calls CreateFunc. func (mock *PersonStoreMock) Create(ctx context.Context, person *Person, confirm bool) error { if mock.CreateFunc == nil { - panic("moq: PersonStoreMock.CreateFunc is nil but PersonStore.Create was just called") + panic("PersonStoreMock.CreateFunc: method is nil but PersonStore.Create was just called") } callInfo := struct { Ctx context.Context @@ -101,7 +101,7 @@ func (mock *PersonStoreMock) CreateCalls() []struct { // Get calls GetFunc. func (mock *PersonStoreMock) Get(ctx context.Context, id string) (*Person, error) { if mock.GetFunc == nil { - panic("moq: PersonStoreMock.GetFunc is nil but PersonStore.Get was just called") + panic("PersonStoreMock.GetFunc: method is nil but PersonStore.Get was just called") } callInfo := struct { Ctx context.Context diff --git a/generate/generated.go b/generate/generated.go index 3b0cc4a..e6ba29a 100644 --- a/generate/generated.go +++ b/generate/generated.go @@ -61,7 +61,7 @@ type MyInterfaceMock struct { // One calls OneFunc. func (mock *MyInterfaceMock) One() bool { if mock.OneFunc == nil { - panic("moq: MyInterfaceMock.OneFunc is nil but MyInterface.One was just called") + panic("MyInterfaceMock.OneFunc: method is nil but MyInterface.One was just called") } callInfo := struct { }{} @@ -87,7 +87,7 @@ func (mock *MyInterfaceMock) OneCalls() []struct { // Three calls ThreeFunc. func (mock *MyInterfaceMock) Three() string { if mock.ThreeFunc == nil { - panic("moq: MyInterfaceMock.ThreeFunc is nil but MyInterface.Three was just called") + panic("MyInterfaceMock.ThreeFunc: method is nil but MyInterface.Three was just called") } callInfo := struct { }{} @@ -113,7 +113,7 @@ func (mock *MyInterfaceMock) ThreeCalls() []struct { // Two calls TwoFunc. func (mock *MyInterfaceMock) Two() int { if mock.TwoFunc == nil { - panic("moq: MyInterfaceMock.TwoFunc is nil but MyInterface.Two was just called") + panic("MyInterfaceMock.TwoFunc: method is nil but MyInterface.Two was just called") } callInfo := struct { }{} diff --git a/pkg/moq/testpackages/dotimport/service_moq_test.go b/pkg/moq/testpackages/dotimport/service_moq_test.go index b3883e5..c8aeb86 100755 --- a/pkg/moq/testpackages/dotimport/service_moq_test.go +++ b/pkg/moq/testpackages/dotimport/service_moq_test.go @@ -44,7 +44,7 @@ type ServiceMock struct { // User calls UserFunc. func (mock *ServiceMock) User(ID string) (dotimport.User, error) { if mock.UserFunc == nil { - panic("moq: ServiceMock.UserFunc is nil but Service.User was just called") + panic("ServiceMock.UserFunc: method is nil but Service.User was just called") } callInfo := struct { ID string diff --git a/pkg/moq/testpackages/gogenvendoring/user/user.go b/pkg/moq/testpackages/gogenvendoring/user/user.go index 6391d05..87f6e29 100644 --- a/pkg/moq/testpackages/gogenvendoring/user/user.go +++ b/pkg/moq/testpackages/gogenvendoring/user/user.go @@ -2,7 +2,7 @@ package user import "github.com/matryer/somerepo" -//go:generate moq . Service +//go:generate moq -out user_moq_test.go . Service // Service does something good with computers. type Service interface { diff --git a/pkg/moq/testpackages/gogenvendoring/user/user_moq_test.go b/pkg/moq/testpackages/gogenvendoring/user/user_moq_test.go new file mode 100644 index 0000000..109b691 --- /dev/null +++ b/pkg/moq/testpackages/gogenvendoring/user/user_moq_test.go @@ -0,0 +1,73 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package user + +import ( + "github.com/matryer/somerepo" + "sync" +) + +var ( + lockServiceMockDoSomething sync.RWMutex +) + +// 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 +}