github.com/PentoHQ/moq@v0.0.0-20190507125140-c45c141f300b/example/mockpersonstore_test.go (about) 1 // Code generated by moq; DO NOT EDIT. 2 // github.com/matryer/moq 3 4 package example 5 6 import ( 7 "context" 8 "sync" 9 ) 10 11 var ( 12 lockPersonStoreMockCreate sync.RWMutex 13 lockPersonStoreMockGet sync.RWMutex 14 ) 15 16 // Ensure, that PersonStoreMock does implement PersonStore. 17 // If this is not the case, regenerate this file with moq. 18 var _ PersonStore = &PersonStoreMock{} 19 20 // PersonStoreMock is a mock implementation of PersonStore. 21 // 22 // func TestSomethingThatUsesPersonStore(t *testing.T) { 23 // 24 // // make and configure a mocked PersonStore 25 // mockedPersonStore := &PersonStoreMock{ 26 // CreateFunc: func(ctx context.Context, person *Person, confirm bool) error { 27 // panic("mock out the Create method") 28 // }, 29 // GetFunc: func(ctx context.Context, id string) (*Person, error) { 30 // panic("mock out the Get method") 31 // }, 32 // } 33 // 34 // // use mockedPersonStore in code that requires PersonStore 35 // // and then make assertions. 36 // 37 // } 38 type PersonStoreMock struct { 39 // CreateFunc mocks the Create method. 40 CreateFunc func(ctx context.Context, person *Person, confirm bool) error 41 42 // GetFunc mocks the Get method. 43 GetFunc func(ctx context.Context, id string) (*Person, error) 44 45 // calls tracks calls to the methods. 46 calls struct { 47 // Create holds details about calls to the Create method. 48 Create []struct { 49 // Ctx is the ctx argument value. 50 Ctx context.Context 51 // Person is the person argument value. 52 Person *Person 53 // Confirm is the confirm argument value. 54 Confirm bool 55 } 56 // Get holds details about calls to the Get method. 57 Get []struct { 58 // Ctx is the ctx argument value. 59 Ctx context.Context 60 // ID is the id argument value. 61 ID string 62 } 63 } 64 } 65 66 // Create calls CreateFunc. 67 func (mock *PersonStoreMock) Create(ctx context.Context, person *Person, confirm bool) error { 68 if mock.CreateFunc == nil { 69 panic("PersonStoreMock.CreateFunc: method is nil but PersonStore.Create was just called") 70 } 71 callInfo := struct { 72 Ctx context.Context 73 Person *Person 74 Confirm bool 75 }{ 76 Ctx: ctx, 77 Person: person, 78 Confirm: confirm, 79 } 80 lockPersonStoreMockCreate.Lock() 81 mock.calls.Create = append(mock.calls.Create, callInfo) 82 lockPersonStoreMockCreate.Unlock() 83 return mock.CreateFunc(ctx, person, confirm) 84 } 85 86 // CreateCalls gets all the calls that were made to Create. 87 // Check the length with: 88 // len(mockedPersonStore.CreateCalls()) 89 func (mock *PersonStoreMock) CreateCalls() []struct { 90 Ctx context.Context 91 Person *Person 92 Confirm bool 93 } { 94 var calls []struct { 95 Ctx context.Context 96 Person *Person 97 Confirm bool 98 } 99 lockPersonStoreMockCreate.RLock() 100 calls = mock.calls.Create 101 lockPersonStoreMockCreate.RUnlock() 102 return calls 103 } 104 105 // Get calls GetFunc. 106 func (mock *PersonStoreMock) Get(ctx context.Context, id string) (*Person, error) { 107 if mock.GetFunc == nil { 108 panic("PersonStoreMock.GetFunc: method is nil but PersonStore.Get was just called") 109 } 110 callInfo := struct { 111 Ctx context.Context 112 ID string 113 }{ 114 Ctx: ctx, 115 ID: id, 116 } 117 lockPersonStoreMockGet.Lock() 118 mock.calls.Get = append(mock.calls.Get, callInfo) 119 lockPersonStoreMockGet.Unlock() 120 return mock.GetFunc(ctx, id) 121 } 122 123 // GetCalls gets all the calls that were made to Get. 124 // Check the length with: 125 // len(mockedPersonStore.GetCalls()) 126 func (mock *PersonStoreMock) GetCalls() []struct { 127 Ctx context.Context 128 ID string 129 } { 130 var calls []struct { 131 Ctx context.Context 132 ID string 133 } 134 lockPersonStoreMockGet.RLock() 135 calls = mock.calls.Get 136 lockPersonStoreMockGet.RUnlock() 137 return calls 138 }