place_thing_repository_minimock.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. // Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
  2. package mocks
  3. //go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place.PlaceThingRepository -o place_thing_repository_minimock.go -n PlaceThingRepositoryMock -p mocks
  4. import (
  5. "context"
  6. "sync"
  7. mm_atomic "sync/atomic"
  8. mm_time "time"
  9. "github.com/gojuno/minimock/v3"
  10. )
  11. // PlaceThingRepositoryMock implements place.PlaceThingRepository
  12. type PlaceThingRepositoryMock struct {
  13. t minimock.Tester
  14. finishOnce sync.Once
  15. funcDeleteThing func(ctx context.Context, id uint64) (err error)
  16. inspectFuncDeleteThing func(ctx context.Context, id uint64)
  17. afterDeleteThingCounter uint64
  18. beforeDeleteThingCounter uint64
  19. DeleteThingMock mPlaceThingRepositoryMockDeleteThing
  20. }
  21. // NewPlaceThingRepositoryMock returns a mock for place.PlaceThingRepository
  22. func NewPlaceThingRepositoryMock(t minimock.Tester) *PlaceThingRepositoryMock {
  23. m := &PlaceThingRepositoryMock{t: t}
  24. if controller, ok := t.(minimock.MockController); ok {
  25. controller.RegisterMocker(m)
  26. }
  27. m.DeleteThingMock = mPlaceThingRepositoryMockDeleteThing{mock: m}
  28. m.DeleteThingMock.callArgs = []*PlaceThingRepositoryMockDeleteThingParams{}
  29. t.Cleanup(m.MinimockFinish)
  30. return m
  31. }
  32. type mPlaceThingRepositoryMockDeleteThing struct {
  33. optional bool
  34. mock *PlaceThingRepositoryMock
  35. defaultExpectation *PlaceThingRepositoryMockDeleteThingExpectation
  36. expectations []*PlaceThingRepositoryMockDeleteThingExpectation
  37. callArgs []*PlaceThingRepositoryMockDeleteThingParams
  38. mutex sync.RWMutex
  39. expectedInvocations uint64
  40. }
  41. // PlaceThingRepositoryMockDeleteThingExpectation specifies expectation struct of the PlaceThingRepository.DeleteThing
  42. type PlaceThingRepositoryMockDeleteThingExpectation struct {
  43. mock *PlaceThingRepositoryMock
  44. params *PlaceThingRepositoryMockDeleteThingParams
  45. paramPtrs *PlaceThingRepositoryMockDeleteThingParamPtrs
  46. results *PlaceThingRepositoryMockDeleteThingResults
  47. Counter uint64
  48. }
  49. // PlaceThingRepositoryMockDeleteThingParams contains parameters of the PlaceThingRepository.DeleteThing
  50. type PlaceThingRepositoryMockDeleteThingParams struct {
  51. ctx context.Context
  52. id uint64
  53. }
  54. // PlaceThingRepositoryMockDeleteThingParamPtrs contains pointers to parameters of the PlaceThingRepository.DeleteThing
  55. type PlaceThingRepositoryMockDeleteThingParamPtrs struct {
  56. ctx *context.Context
  57. id *uint64
  58. }
  59. // PlaceThingRepositoryMockDeleteThingResults contains results of the PlaceThingRepository.DeleteThing
  60. type PlaceThingRepositoryMockDeleteThingResults struct {
  61. err error
  62. }
  63. // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
  64. // the test will fail minimock's automatic final call check if the mocked method was not called at least once.
  65. // Optional() makes method check to work in '0 or more' mode.
  66. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
  67. // catch the problems when the expected method call is totally skipped during test run.
  68. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Optional() *mPlaceThingRepositoryMockDeleteThing {
  69. mmDeleteThing.optional = true
  70. return mmDeleteThing
  71. }
  72. // Expect sets up expected params for PlaceThingRepository.DeleteThing
  73. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Expect(ctx context.Context, id uint64) *mPlaceThingRepositoryMockDeleteThing {
  74. if mmDeleteThing.mock.funcDeleteThing != nil {
  75. mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
  76. }
  77. if mmDeleteThing.defaultExpectation == nil {
  78. mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{}
  79. }
  80. if mmDeleteThing.defaultExpectation.paramPtrs != nil {
  81. mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by ExpectParams functions")
  82. }
  83. mmDeleteThing.defaultExpectation.params = &PlaceThingRepositoryMockDeleteThingParams{ctx, id}
  84. for _, e := range mmDeleteThing.expectations {
  85. if minimock.Equal(e.params, mmDeleteThing.defaultExpectation.params) {
  86. mmDeleteThing.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteThing.defaultExpectation.params)
  87. }
  88. }
  89. return mmDeleteThing
  90. }
  91. // ExpectCtxParam1 sets up expected param ctx for PlaceThingRepository.DeleteThing
  92. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectCtxParam1(ctx context.Context) *mPlaceThingRepositoryMockDeleteThing {
  93. if mmDeleteThing.mock.funcDeleteThing != nil {
  94. mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
  95. }
  96. if mmDeleteThing.defaultExpectation == nil {
  97. mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{}
  98. }
  99. if mmDeleteThing.defaultExpectation.params != nil {
  100. mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Expect")
  101. }
  102. if mmDeleteThing.defaultExpectation.paramPtrs == nil {
  103. mmDeleteThing.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockDeleteThingParamPtrs{}
  104. }
  105. mmDeleteThing.defaultExpectation.paramPtrs.ctx = &ctx
  106. return mmDeleteThing
  107. }
  108. // ExpectIdParam2 sets up expected param id for PlaceThingRepository.DeleteThing
  109. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectIdParam2(id uint64) *mPlaceThingRepositoryMockDeleteThing {
  110. if mmDeleteThing.mock.funcDeleteThing != nil {
  111. mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
  112. }
  113. if mmDeleteThing.defaultExpectation == nil {
  114. mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{}
  115. }
  116. if mmDeleteThing.defaultExpectation.params != nil {
  117. mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Expect")
  118. }
  119. if mmDeleteThing.defaultExpectation.paramPtrs == nil {
  120. mmDeleteThing.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockDeleteThingParamPtrs{}
  121. }
  122. mmDeleteThing.defaultExpectation.paramPtrs.id = &id
  123. return mmDeleteThing
  124. }
  125. // Inspect accepts an inspector function that has same arguments as the PlaceThingRepository.DeleteThing
  126. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Inspect(f func(ctx context.Context, id uint64)) *mPlaceThingRepositoryMockDeleteThing {
  127. if mmDeleteThing.mock.inspectFuncDeleteThing != nil {
  128. mmDeleteThing.mock.t.Fatalf("Inspect function is already set for PlaceThingRepositoryMock.DeleteThing")
  129. }
  130. mmDeleteThing.mock.inspectFuncDeleteThing = f
  131. return mmDeleteThing
  132. }
  133. // Return sets up results that will be returned by PlaceThingRepository.DeleteThing
  134. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Return(err error) *PlaceThingRepositoryMock {
  135. if mmDeleteThing.mock.funcDeleteThing != nil {
  136. mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
  137. }
  138. if mmDeleteThing.defaultExpectation == nil {
  139. mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{mock: mmDeleteThing.mock}
  140. }
  141. mmDeleteThing.defaultExpectation.results = &PlaceThingRepositoryMockDeleteThingResults{err}
  142. return mmDeleteThing.mock
  143. }
  144. // Set uses given function f to mock the PlaceThingRepository.DeleteThing method
  145. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Set(f func(ctx context.Context, id uint64) (err error)) *PlaceThingRepositoryMock {
  146. if mmDeleteThing.defaultExpectation != nil {
  147. mmDeleteThing.mock.t.Fatalf("Default expectation is already set for the PlaceThingRepository.DeleteThing method")
  148. }
  149. if len(mmDeleteThing.expectations) > 0 {
  150. mmDeleteThing.mock.t.Fatalf("Some expectations are already set for the PlaceThingRepository.DeleteThing method")
  151. }
  152. mmDeleteThing.mock.funcDeleteThing = f
  153. return mmDeleteThing.mock
  154. }
  155. // When sets expectation for the PlaceThingRepository.DeleteThing which will trigger the result defined by the following
  156. // Then helper
  157. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) When(ctx context.Context, id uint64) *PlaceThingRepositoryMockDeleteThingExpectation {
  158. if mmDeleteThing.mock.funcDeleteThing != nil {
  159. mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
  160. }
  161. expectation := &PlaceThingRepositoryMockDeleteThingExpectation{
  162. mock: mmDeleteThing.mock,
  163. params: &PlaceThingRepositoryMockDeleteThingParams{ctx, id},
  164. }
  165. mmDeleteThing.expectations = append(mmDeleteThing.expectations, expectation)
  166. return expectation
  167. }
  168. // Then sets up PlaceThingRepository.DeleteThing return parameters for the expectation previously defined by the When method
  169. func (e *PlaceThingRepositoryMockDeleteThingExpectation) Then(err error) *PlaceThingRepositoryMock {
  170. e.results = &PlaceThingRepositoryMockDeleteThingResults{err}
  171. return e.mock
  172. }
  173. // Times sets number of times PlaceThingRepository.DeleteThing should be invoked
  174. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Times(n uint64) *mPlaceThingRepositoryMockDeleteThing {
  175. if n == 0 {
  176. mmDeleteThing.mock.t.Fatalf("Times of PlaceThingRepositoryMock.DeleteThing mock can not be zero")
  177. }
  178. mm_atomic.StoreUint64(&mmDeleteThing.expectedInvocations, n)
  179. return mmDeleteThing
  180. }
  181. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) invocationsDone() bool {
  182. if len(mmDeleteThing.expectations) == 0 && mmDeleteThing.defaultExpectation == nil && mmDeleteThing.mock.funcDeleteThing == nil {
  183. return true
  184. }
  185. totalInvocations := mm_atomic.LoadUint64(&mmDeleteThing.mock.afterDeleteThingCounter)
  186. expectedInvocations := mm_atomic.LoadUint64(&mmDeleteThing.expectedInvocations)
  187. return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
  188. }
  189. // DeleteThing implements place.PlaceThingRepository
  190. func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context, id uint64) (err error) {
  191. mm_atomic.AddUint64(&mmDeleteThing.beforeDeleteThingCounter, 1)
  192. defer mm_atomic.AddUint64(&mmDeleteThing.afterDeleteThingCounter, 1)
  193. if mmDeleteThing.inspectFuncDeleteThing != nil {
  194. mmDeleteThing.inspectFuncDeleteThing(ctx, id)
  195. }
  196. mm_params := PlaceThingRepositoryMockDeleteThingParams{ctx, id}
  197. // Record call args
  198. mmDeleteThing.DeleteThingMock.mutex.Lock()
  199. mmDeleteThing.DeleteThingMock.callArgs = append(mmDeleteThing.DeleteThingMock.callArgs, &mm_params)
  200. mmDeleteThing.DeleteThingMock.mutex.Unlock()
  201. for _, e := range mmDeleteThing.DeleteThingMock.expectations {
  202. if minimock.Equal(*e.params, mm_params) {
  203. mm_atomic.AddUint64(&e.Counter, 1)
  204. return e.results.err
  205. }
  206. }
  207. if mmDeleteThing.DeleteThingMock.defaultExpectation != nil {
  208. mm_atomic.AddUint64(&mmDeleteThing.DeleteThingMock.defaultExpectation.Counter, 1)
  209. mm_want := mmDeleteThing.DeleteThingMock.defaultExpectation.params
  210. mm_want_ptrs := mmDeleteThing.DeleteThingMock.defaultExpectation.paramPtrs
  211. mm_got := PlaceThingRepositoryMockDeleteThingParams{ctx, id}
  212. if mm_want_ptrs != nil {
  213. if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
  214. mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
  215. }
  216. if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
  217. mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
  218. }
  219. } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  220. mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  221. }
  222. mm_results := mmDeleteThing.DeleteThingMock.defaultExpectation.results
  223. if mm_results == nil {
  224. mmDeleteThing.t.Fatal("No results are set for the PlaceThingRepositoryMock.DeleteThing")
  225. }
  226. return (*mm_results).err
  227. }
  228. if mmDeleteThing.funcDeleteThing != nil {
  229. return mmDeleteThing.funcDeleteThing(ctx, id)
  230. }
  231. mmDeleteThing.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.DeleteThing. %v %v", ctx, id)
  232. return
  233. }
  234. // DeleteThingAfterCounter returns a count of finished PlaceThingRepositoryMock.DeleteThing invocations
  235. func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThingAfterCounter() uint64 {
  236. return mm_atomic.LoadUint64(&mmDeleteThing.afterDeleteThingCounter)
  237. }
  238. // DeleteThingBeforeCounter returns a count of PlaceThingRepositoryMock.DeleteThing invocations
  239. func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThingBeforeCounter() uint64 {
  240. return mm_atomic.LoadUint64(&mmDeleteThing.beforeDeleteThingCounter)
  241. }
  242. // Calls returns a list of arguments used in each call to PlaceThingRepositoryMock.DeleteThing.
  243. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  244. func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Calls() []*PlaceThingRepositoryMockDeleteThingParams {
  245. mmDeleteThing.mutex.RLock()
  246. argCopy := make([]*PlaceThingRepositoryMockDeleteThingParams, len(mmDeleteThing.callArgs))
  247. copy(argCopy, mmDeleteThing.callArgs)
  248. mmDeleteThing.mutex.RUnlock()
  249. return argCopy
  250. }
  251. // MinimockDeleteThingDone returns true if the count of the DeleteThing invocations corresponds
  252. // the number of defined expectations
  253. func (m *PlaceThingRepositoryMock) MinimockDeleteThingDone() bool {
  254. if m.DeleteThingMock.optional {
  255. // Optional methods provide '0 or more' call count restriction.
  256. return true
  257. }
  258. for _, e := range m.DeleteThingMock.expectations {
  259. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  260. return false
  261. }
  262. }
  263. return m.DeleteThingMock.invocationsDone()
  264. }
  265. // MinimockDeleteThingInspect logs each unmet expectation
  266. func (m *PlaceThingRepositoryMock) MinimockDeleteThingInspect() {
  267. for _, e := range m.DeleteThingMock.expectations {
  268. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  269. m.t.Errorf("Expected call to PlaceThingRepositoryMock.DeleteThing with params: %#v", *e.params)
  270. }
  271. }
  272. afterDeleteThingCounter := mm_atomic.LoadUint64(&m.afterDeleteThingCounter)
  273. // if default expectation was set then invocations count should be greater than zero
  274. if m.DeleteThingMock.defaultExpectation != nil && afterDeleteThingCounter < 1 {
  275. if m.DeleteThingMock.defaultExpectation.params == nil {
  276. m.t.Error("Expected call to PlaceThingRepositoryMock.DeleteThing")
  277. } else {
  278. m.t.Errorf("Expected call to PlaceThingRepositoryMock.DeleteThing with params: %#v", *m.DeleteThingMock.defaultExpectation.params)
  279. }
  280. }
  281. // if func was set then invocations count should be greater than zero
  282. if m.funcDeleteThing != nil && afterDeleteThingCounter < 1 {
  283. m.t.Error("Expected call to PlaceThingRepositoryMock.DeleteThing")
  284. }
  285. if !m.DeleteThingMock.invocationsDone() && afterDeleteThingCounter > 0 {
  286. m.t.Errorf("Expected %d calls to PlaceThingRepositoryMock.DeleteThing but found %d calls",
  287. mm_atomic.LoadUint64(&m.DeleteThingMock.expectedInvocations), afterDeleteThingCounter)
  288. }
  289. }
  290. // MinimockFinish checks that all mocked methods have been called the expected number of times
  291. func (m *PlaceThingRepositoryMock) MinimockFinish() {
  292. m.finishOnce.Do(func() {
  293. if !m.minimockDone() {
  294. m.MinimockDeleteThingInspect()
  295. }
  296. })
  297. }
  298. // MinimockWait waits for all mocked methods to be called the expected number of times
  299. func (m *PlaceThingRepositoryMock) MinimockWait(timeout mm_time.Duration) {
  300. timeoutCh := mm_time.After(timeout)
  301. for {
  302. if m.minimockDone() {
  303. return
  304. }
  305. select {
  306. case <-timeoutCh:
  307. m.MinimockFinish()
  308. return
  309. case <-mm_time.After(10 * mm_time.Millisecond):
  310. }
  311. }
  312. }
  313. func (m *PlaceThingRepositoryMock) minimockDone() bool {
  314. done := true
  315. return done &&
  316. m.MinimockDeleteThingDone()
  317. }