github.com/rancher/moq@v0.0.0-20200712062324-13d1f37d2d77/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 // Ensure, that ServiceMock does implement dotimport.Service. 16 // If this is not the case, regenerate this file with moq. 17 var _ dotimport.Service = &ServiceMock{} 18 19 // ServiceMock is a mock implementation of dotimport.Service. 20 // 21 // func TestSomethingThatUsesService(t *testing.T) { 22 // 23 // // make and configure a mocked dotimport.Service 24 // mockedService := &ServiceMock{ 25 // UserFunc: func(ID string) (dotimport.User, error) { 26 // panic("mock out the User method") 27 // }, 28 // } 29 // 30 // // use mockedService in code that requires dotimport.Service 31 // // and then make assertions. 32 // 33 // } 34 type ServiceMock struct { 35 // UserFunc mocks the User method. 36 UserFunc func(ID string) (dotimport.User, error) 37 38 // calls tracks calls to the methods. 39 calls struct { 40 // User holds details about calls to the User method. 41 User []struct { 42 // ID is the ID argument value. 43 ID string 44 } 45 } 46 } 47 48 // User calls UserFunc. 49 func (mock *ServiceMock) User(ID string) (dotimport.User, error) { 50 if mock.UserFunc == nil { 51 panic("ServiceMock.UserFunc: method is nil but Service.User was just called") 52 } 53 callInfo := struct { 54 ID string 55 }{ 56 ID: ID, 57 } 58 lockServiceMockUser.Lock() 59 mock.calls.User = append(mock.calls.User, callInfo) 60 lockServiceMockUser.Unlock() 61 return mock.UserFunc(ID) 62 } 63 64 // UserCalls gets all the calls that were made to User. 65 // Check the length with: 66 // len(mockedService.UserCalls()) 67 func (mock *ServiceMock) UserCalls() []struct { 68 ID string 69 } { 70 var calls []struct { 71 ID string 72 } 73 lockServiceMockUser.RLock() 74 calls = mock.calls.User 75 lockServiceMockUser.RUnlock() 76 return calls 77 }