github.com/GetStream/moq@v0.0.0-20181113105103-b721cd3f6524/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 // PersonStoreMock is a mock implementation of PersonStore. 17 // 18 // func TestSomethingThatUsesPersonStore(t *testing.T) { 19 // 20 // // make and configure a mocked PersonStore 21 // mockedPersonStore := &PersonStoreMock{ 22 // CreateFunc: func(ctx context.Context, person *Person, confirm bool) error { 23 // panic("TODO: mock out the Create method") 24 // }, 25 // GetFunc: func(ctx context.Context, id string) (*Person, error) { 26 // panic("TODO: mock out the Get method") 27 // }, 28 // } 29 // 30 // // TODO: use mockedPersonStore in code that requires PersonStore 31 // // and then make assertions. 32 // 33 // } 34 type PersonStoreMock struct { 35 // CreateFunc mocks the Create method. 36 CreateFunc func(ctx context.Context, person *Person, confirm bool) error 37 38 // GetFunc mocks the Get method. 39 GetFunc func(ctx context.Context, id string) (*Person, error) 40 41 // calls tracks calls to the methods. 42 calls struct { 43 // Create holds details about calls to the Create method. 44 Create []struct { 45 // Ctx is the ctx argument value. 46 Ctx context.Context 47 // Person is the person argument value. 48 Person *Person 49 // Confirm is the confirm argument value. 50 Confirm bool 51 } 52 // Get holds details about calls to the Get method. 53 Get []struct { 54 // Ctx is the ctx argument value. 55 Ctx context.Context 56 // ID is the id argument value. 57 ID string 58 } 59 } 60 } 61 62 // Create calls CreateFunc. 63 func (mock *PersonStoreMock) Create(ctx context.Context, person *Person, confirm bool) error { 64 if mock.CreateFunc == nil { 65 panic("PersonStoreMock.CreateFunc: method is nil but PersonStore.Create was just called") 66 } 67 callInfo := struct { 68 Ctx context.Context 69 Person *Person 70 Confirm bool 71 }{ 72 Ctx: ctx, 73 Person: person, 74 Confirm: confirm, 75 } 76 lockPersonStoreMockCreate.Lock() 77 mock.calls.Create = append(mock.calls.Create, callInfo) 78 lockPersonStoreMockCreate.Unlock() 79 return mock.CreateFunc(ctx, person, confirm) 80 } 81 82 // CreateCalls gets all the calls that were made to Create. 83 // Check the length with: 84 // len(mockedPersonStore.CreateCalls()) 85 func (mock *PersonStoreMock) CreateCalls() []struct { 86 Ctx context.Context 87 Person *Person 88 Confirm bool 89 } { 90 var calls []struct { 91 Ctx context.Context 92 Person *Person 93 Confirm bool 94 } 95 lockPersonStoreMockCreate.RLock() 96 calls = mock.calls.Create 97 lockPersonStoreMockCreate.RUnlock() 98 return calls 99 } 100 101 // Get calls GetFunc. 102 func (mock *PersonStoreMock) Get(ctx context.Context, id string) (*Person, error) { 103 if mock.GetFunc == nil { 104 panic("PersonStoreMock.GetFunc: method is nil but PersonStore.Get was just called") 105 } 106 callInfo := struct { 107 Ctx context.Context 108 ID string 109 }{ 110 Ctx: ctx, 111 ID: id, 112 } 113 lockPersonStoreMockGet.Lock() 114 mock.calls.Get = append(mock.calls.Get, callInfo) 115 lockPersonStoreMockGet.Unlock() 116 return mock.GetFunc(ctx, id) 117 } 118 119 // GetCalls gets all the calls that were made to Get. 120 // Check the length with: 121 // len(mockedPersonStore.GetCalls()) 122 func (mock *PersonStoreMock) GetCalls() []struct { 123 Ctx context.Context 124 ID string 125 } { 126 var calls []struct { 127 Ctx context.Context 128 ID string 129 } 130 lockPersonStoreMockGet.RLock() 131 calls = mock.calls.Get 132 lockPersonStoreMockGet.RUnlock() 133 return calls 134 }