github.com/GetStream/moq@v0.0.0-20181113105103-b721cd3f6524/pkg/moq/testpackages/gogenvendoring/user/user_moq_test.go (about) 1 // Code generated by moq; DO NOT EDIT. 2 // github.com/matryer/moq 3 4 package user 5 6 import ( 7 "github.com/matryer/somerepo" 8 "sync" 9 ) 10 11 var ( 12 lockServiceMockDoSomething sync.RWMutex 13 ) 14 15 // ServiceMock is a mock implementation of Service. 16 // 17 // func TestSomethingThatUsesService(t *testing.T) { 18 // 19 // // make and configure a mocked Service 20 // mockedService := &ServiceMock{ 21 // DoSomethingFunc: func(in1 somerepo.SomeType) error { 22 // panic("TODO: mock out the DoSomething method") 23 // }, 24 // } 25 // 26 // // TODO: use mockedService in code that requires Service 27 // // and then make assertions. 28 // 29 // } 30 type ServiceMock struct { 31 // DoSomethingFunc mocks the DoSomething method. 32 DoSomethingFunc func(in1 somerepo.SomeType) error 33 34 // calls tracks calls to the methods. 35 calls struct { 36 // DoSomething holds details about calls to the DoSomething method. 37 DoSomething []struct { 38 // In1 is the in1 argument value. 39 In1 somerepo.SomeType 40 } 41 } 42 } 43 44 // DoSomething calls DoSomethingFunc. 45 func (mock *ServiceMock) DoSomething(in1 somerepo.SomeType) error { 46 if mock.DoSomethingFunc == nil { 47 panic("ServiceMock.DoSomethingFunc: method is nil but Service.DoSomething was just called") 48 } 49 callInfo := struct { 50 In1 somerepo.SomeType 51 }{ 52 In1: in1, 53 } 54 lockServiceMockDoSomething.Lock() 55 mock.calls.DoSomething = append(mock.calls.DoSomething, callInfo) 56 lockServiceMockDoSomething.Unlock() 57 return mock.DoSomethingFunc(in1) 58 } 59 60 // DoSomethingCalls gets all the calls that were made to DoSomething. 61 // Check the length with: 62 // len(mockedService.DoSomethingCalls()) 63 func (mock *ServiceMock) DoSomethingCalls() []struct { 64 In1 somerepo.SomeType 65 } { 66 var calls []struct { 67 In1 somerepo.SomeType 68 } 69 lockServiceMockDoSomething.RLock() 70 calls = mock.calls.DoSomething 71 lockServiceMockDoSomething.RUnlock() 72 return calls 73 }