github.com/GetStream/moq@v0.0.0-20181113105103-b721cd3f6524/pkg/moq/testpackages/dotimport/service_moq_test.go (about) 1 // Code generated by moq; DO NOT EDIT. 2 // github.com/matryer/moq 3 4 package dotimport_test 5 6 import ( 7 "github.com/matryer/moq/pkg/moq/testpackages/dotimport" 8 "sync" 9 ) 10 11 var ( 12 lockServiceMockUser 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 // UserFunc: func(ID string) (dotimport.User, error) { 22 // panic("TODO: mock out the User 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 // UserFunc mocks the User method. 32 UserFunc func(ID string) (dotimport.User, error) 33 34 // calls tracks calls to the methods. 35 calls struct { 36 // User holds details about calls to the User method. 37 User []struct { 38 // ID is the ID argument value. 39 ID string 40 } 41 } 42 } 43 44 // User calls UserFunc. 45 func (mock *ServiceMock) User(ID string) (dotimport.User, error) { 46 if mock.UserFunc == nil { 47 panic("ServiceMock.UserFunc: method is nil but Service.User was just called") 48 } 49 callInfo := struct { 50 ID string 51 }{ 52 ID: ID, 53 } 54 lockServiceMockUser.Lock() 55 mock.calls.User = append(mock.calls.User, callInfo) 56 lockServiceMockUser.Unlock() 57 return mock.UserFunc(ID) 58 } 59 60 // UserCalls gets all the calls that were made to User. 61 // Check the length with: 62 // len(mockedService.UserCalls()) 63 func (mock *ServiceMock) UserCalls() []struct { 64 ID string 65 } { 66 var calls []struct { 67 ID string 68 } 69 lockServiceMockUser.RLock() 70 calls = mock.calls.User 71 lockServiceMockUser.RUnlock() 72 return calls 73 }