thing_notification_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/thing.ThingNotificationRepository -o thing_notification_repository_minimock.go -n ThingNotificationRepositoryMock -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. // ThingNotificationRepositoryMock implements thing.ThingNotificationRepository
  12. type ThingNotificationRepositoryMock struct {
  13. t minimock.Tester
  14. finishOnce sync.Once
  15. funcDelete func(ctx context.Context, id uint64) (err error)
  16. inspectFuncDelete func(ctx context.Context, id uint64)
  17. afterDeleteCounter uint64
  18. beforeDeleteCounter uint64
  19. DeleteMock mThingNotificationRepositoryMockDelete
  20. }
  21. // NewThingNotificationRepositoryMock returns a mock for thing.ThingNotificationRepository
  22. func NewThingNotificationRepositoryMock(t minimock.Tester) *ThingNotificationRepositoryMock {
  23. m := &ThingNotificationRepositoryMock{t: t}
  24. if controller, ok := t.(minimock.MockController); ok {
  25. controller.RegisterMocker(m)
  26. }
  27. m.DeleteMock = mThingNotificationRepositoryMockDelete{mock: m}
  28. m.DeleteMock.callArgs = []*ThingNotificationRepositoryMockDeleteParams{}
  29. t.Cleanup(m.MinimockFinish)
  30. return m
  31. }
  32. type mThingNotificationRepositoryMockDelete struct {
  33. optional bool
  34. mock *ThingNotificationRepositoryMock
  35. defaultExpectation *ThingNotificationRepositoryMockDeleteExpectation
  36. expectations []*ThingNotificationRepositoryMockDeleteExpectation
  37. callArgs []*ThingNotificationRepositoryMockDeleteParams
  38. mutex sync.RWMutex
  39. expectedInvocations uint64
  40. }
  41. // ThingNotificationRepositoryMockDeleteExpectation specifies expectation struct of the ThingNotificationRepository.Delete
  42. type ThingNotificationRepositoryMockDeleteExpectation struct {
  43. mock *ThingNotificationRepositoryMock
  44. params *ThingNotificationRepositoryMockDeleteParams
  45. paramPtrs *ThingNotificationRepositoryMockDeleteParamPtrs
  46. results *ThingNotificationRepositoryMockDeleteResults
  47. Counter uint64
  48. }
  49. // ThingNotificationRepositoryMockDeleteParams contains parameters of the ThingNotificationRepository.Delete
  50. type ThingNotificationRepositoryMockDeleteParams struct {
  51. ctx context.Context
  52. id uint64
  53. }
  54. // ThingNotificationRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingNotificationRepository.Delete
  55. type ThingNotificationRepositoryMockDeleteParamPtrs struct {
  56. ctx *context.Context
  57. id *uint64
  58. }
  59. // ThingNotificationRepositoryMockDeleteResults contains results of the ThingNotificationRepository.Delete
  60. type ThingNotificationRepositoryMockDeleteResults 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 (mmDelete *mThingNotificationRepositoryMockDelete) Optional() *mThingNotificationRepositoryMockDelete {
  69. mmDelete.optional = true
  70. return mmDelete
  71. }
  72. // Expect sets up expected params for ThingNotificationRepository.Delete
  73. func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Context, id uint64) *mThingNotificationRepositoryMockDelete {
  74. if mmDelete.mock.funcDelete != nil {
  75. mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
  76. }
  77. if mmDelete.defaultExpectation == nil {
  78. mmDelete.defaultExpectation = &ThingNotificationRepositoryMockDeleteExpectation{}
  79. }
  80. if mmDelete.defaultExpectation.paramPtrs != nil {
  81. mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by ExpectParams functions")
  82. }
  83. mmDelete.defaultExpectation.params = &ThingNotificationRepositoryMockDeleteParams{ctx, id}
  84. for _, e := range mmDelete.expectations {
  85. if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
  86. mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
  87. }
  88. }
  89. return mmDelete
  90. }
  91. // ExpectCtxParam1 sets up expected param ctx for ThingNotificationRepository.Delete
  92. func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectCtxParam1(ctx context.Context) *mThingNotificationRepositoryMockDelete {
  93. if mmDelete.mock.funcDelete != nil {
  94. mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
  95. }
  96. if mmDelete.defaultExpectation == nil {
  97. mmDelete.defaultExpectation = &ThingNotificationRepositoryMockDeleteExpectation{}
  98. }
  99. if mmDelete.defaultExpectation.params != nil {
  100. mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Expect")
  101. }
  102. if mmDelete.defaultExpectation.paramPtrs == nil {
  103. mmDelete.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockDeleteParamPtrs{}
  104. }
  105. mmDelete.defaultExpectation.paramPtrs.ctx = &ctx
  106. return mmDelete
  107. }
  108. // ExpectIdParam2 sets up expected param id for ThingNotificationRepository.Delete
  109. func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectIdParam2(id uint64) *mThingNotificationRepositoryMockDelete {
  110. if mmDelete.mock.funcDelete != nil {
  111. mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
  112. }
  113. if mmDelete.defaultExpectation == nil {
  114. mmDelete.defaultExpectation = &ThingNotificationRepositoryMockDeleteExpectation{}
  115. }
  116. if mmDelete.defaultExpectation.params != nil {
  117. mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Expect")
  118. }
  119. if mmDelete.defaultExpectation.paramPtrs == nil {
  120. mmDelete.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockDeleteParamPtrs{}
  121. }
  122. mmDelete.defaultExpectation.paramPtrs.id = &id
  123. return mmDelete
  124. }
  125. // Inspect accepts an inspector function that has same arguments as the ThingNotificationRepository.Delete
  126. func (mmDelete *mThingNotificationRepositoryMockDelete) Inspect(f func(ctx context.Context, id uint64)) *mThingNotificationRepositoryMockDelete {
  127. if mmDelete.mock.inspectFuncDelete != nil {
  128. mmDelete.mock.t.Fatalf("Inspect function is already set for ThingNotificationRepositoryMock.Delete")
  129. }
  130. mmDelete.mock.inspectFuncDelete = f
  131. return mmDelete
  132. }
  133. // Return sets up results that will be returned by ThingNotificationRepository.Delete
  134. func (mmDelete *mThingNotificationRepositoryMockDelete) Return(err error) *ThingNotificationRepositoryMock {
  135. if mmDelete.mock.funcDelete != nil {
  136. mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
  137. }
  138. if mmDelete.defaultExpectation == nil {
  139. mmDelete.defaultExpectation = &ThingNotificationRepositoryMockDeleteExpectation{mock: mmDelete.mock}
  140. }
  141. mmDelete.defaultExpectation.results = &ThingNotificationRepositoryMockDeleteResults{err}
  142. return mmDelete.mock
  143. }
  144. // Set uses given function f to mock the ThingNotificationRepository.Delete method
  145. func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.Context, id uint64) (err error)) *ThingNotificationRepositoryMock {
  146. if mmDelete.defaultExpectation != nil {
  147. mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingNotificationRepository.Delete method")
  148. }
  149. if len(mmDelete.expectations) > 0 {
  150. mmDelete.mock.t.Fatalf("Some expectations are already set for the ThingNotificationRepository.Delete method")
  151. }
  152. mmDelete.mock.funcDelete = f
  153. return mmDelete.mock
  154. }
  155. // When sets expectation for the ThingNotificationRepository.Delete which will trigger the result defined by the following
  156. // Then helper
  157. func (mmDelete *mThingNotificationRepositoryMockDelete) When(ctx context.Context, id uint64) *ThingNotificationRepositoryMockDeleteExpectation {
  158. if mmDelete.mock.funcDelete != nil {
  159. mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
  160. }
  161. expectation := &ThingNotificationRepositoryMockDeleteExpectation{
  162. mock: mmDelete.mock,
  163. params: &ThingNotificationRepositoryMockDeleteParams{ctx, id},
  164. }
  165. mmDelete.expectations = append(mmDelete.expectations, expectation)
  166. return expectation
  167. }
  168. // Then sets up ThingNotificationRepository.Delete return parameters for the expectation previously defined by the When method
  169. func (e *ThingNotificationRepositoryMockDeleteExpectation) Then(err error) *ThingNotificationRepositoryMock {
  170. e.results = &ThingNotificationRepositoryMockDeleteResults{err}
  171. return e.mock
  172. }
  173. // Times sets number of times ThingNotificationRepository.Delete should be invoked
  174. func (mmDelete *mThingNotificationRepositoryMockDelete) Times(n uint64) *mThingNotificationRepositoryMockDelete {
  175. if n == 0 {
  176. mmDelete.mock.t.Fatalf("Times of ThingNotificationRepositoryMock.Delete mock can not be zero")
  177. }
  178. mm_atomic.StoreUint64(&mmDelete.expectedInvocations, n)
  179. return mmDelete
  180. }
  181. func (mmDelete *mThingNotificationRepositoryMockDelete) invocationsDone() bool {
  182. if len(mmDelete.expectations) == 0 && mmDelete.defaultExpectation == nil && mmDelete.mock.funcDelete == nil {
  183. return true
  184. }
  185. totalInvocations := mm_atomic.LoadUint64(&mmDelete.mock.afterDeleteCounter)
  186. expectedInvocations := mm_atomic.LoadUint64(&mmDelete.expectedInvocations)
  187. return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
  188. }
  189. // Delete implements thing.ThingNotificationRepository
  190. func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, id uint64) (err error) {
  191. mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
  192. defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
  193. if mmDelete.inspectFuncDelete != nil {
  194. mmDelete.inspectFuncDelete(ctx, id)
  195. }
  196. mm_params := ThingNotificationRepositoryMockDeleteParams{ctx, id}
  197. // Record call args
  198. mmDelete.DeleteMock.mutex.Lock()
  199. mmDelete.DeleteMock.callArgs = append(mmDelete.DeleteMock.callArgs, &mm_params)
  200. mmDelete.DeleteMock.mutex.Unlock()
  201. for _, e := range mmDelete.DeleteMock.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 mmDelete.DeleteMock.defaultExpectation != nil {
  208. mm_atomic.AddUint64(&mmDelete.DeleteMock.defaultExpectation.Counter, 1)
  209. mm_want := mmDelete.DeleteMock.defaultExpectation.params
  210. mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
  211. mm_got := ThingNotificationRepositoryMockDeleteParams{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. mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete 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. mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete 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. mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  221. }
  222. mm_results := mmDelete.DeleteMock.defaultExpectation.results
  223. if mm_results == nil {
  224. mmDelete.t.Fatal("No results are set for the ThingNotificationRepositoryMock.Delete")
  225. }
  226. return (*mm_results).err
  227. }
  228. if mmDelete.funcDelete != nil {
  229. return mmDelete.funcDelete(ctx, id)
  230. }
  231. mmDelete.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Delete. %v %v", ctx, id)
  232. return
  233. }
  234. // DeleteAfterCounter returns a count of finished ThingNotificationRepositoryMock.Delete invocations
  235. func (mmDelete *ThingNotificationRepositoryMock) DeleteAfterCounter() uint64 {
  236. return mm_atomic.LoadUint64(&mmDelete.afterDeleteCounter)
  237. }
  238. // DeleteBeforeCounter returns a count of ThingNotificationRepositoryMock.Delete invocations
  239. func (mmDelete *ThingNotificationRepositoryMock) DeleteBeforeCounter() uint64 {
  240. return mm_atomic.LoadUint64(&mmDelete.beforeDeleteCounter)
  241. }
  242. // Calls returns a list of arguments used in each call to ThingNotificationRepositoryMock.Delete.
  243. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  244. func (mmDelete *mThingNotificationRepositoryMockDelete) Calls() []*ThingNotificationRepositoryMockDeleteParams {
  245. mmDelete.mutex.RLock()
  246. argCopy := make([]*ThingNotificationRepositoryMockDeleteParams, len(mmDelete.callArgs))
  247. copy(argCopy, mmDelete.callArgs)
  248. mmDelete.mutex.RUnlock()
  249. return argCopy
  250. }
  251. // MinimockDeleteDone returns true if the count of the Delete invocations corresponds
  252. // the number of defined expectations
  253. func (m *ThingNotificationRepositoryMock) MinimockDeleteDone() bool {
  254. if m.DeleteMock.optional {
  255. // Optional methods provide '0 or more' call count restriction.
  256. return true
  257. }
  258. for _, e := range m.DeleteMock.expectations {
  259. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  260. return false
  261. }
  262. }
  263. return m.DeleteMock.invocationsDone()
  264. }
  265. // MinimockDeleteInspect logs each unmet expectation
  266. func (m *ThingNotificationRepositoryMock) MinimockDeleteInspect() {
  267. for _, e := range m.DeleteMock.expectations {
  268. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  269. m.t.Errorf("Expected call to ThingNotificationRepositoryMock.Delete with params: %#v", *e.params)
  270. }
  271. }
  272. afterDeleteCounter := mm_atomic.LoadUint64(&m.afterDeleteCounter)
  273. // if default expectation was set then invocations count should be greater than zero
  274. if m.DeleteMock.defaultExpectation != nil && afterDeleteCounter < 1 {
  275. if m.DeleteMock.defaultExpectation.params == nil {
  276. m.t.Error("Expected call to ThingNotificationRepositoryMock.Delete")
  277. } else {
  278. m.t.Errorf("Expected call to ThingNotificationRepositoryMock.Delete with params: %#v", *m.DeleteMock.defaultExpectation.params)
  279. }
  280. }
  281. // if func was set then invocations count should be greater than zero
  282. if m.funcDelete != nil && afterDeleteCounter < 1 {
  283. m.t.Error("Expected call to ThingNotificationRepositoryMock.Delete")
  284. }
  285. if !m.DeleteMock.invocationsDone() && afterDeleteCounter > 0 {
  286. m.t.Errorf("Expected %d calls to ThingNotificationRepositoryMock.Delete but found %d calls",
  287. mm_atomic.LoadUint64(&m.DeleteMock.expectedInvocations), afterDeleteCounter)
  288. }
  289. }
  290. // MinimockFinish checks that all mocked methods have been called the expected number of times
  291. func (m *ThingNotificationRepositoryMock) MinimockFinish() {
  292. m.finishOnce.Do(func() {
  293. if !m.minimockDone() {
  294. m.MinimockDeleteInspect()
  295. }
  296. })
  297. }
  298. // MinimockWait waits for all mocked methods to be called the expected number of times
  299. func (m *ThingNotificationRepositoryMock) 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 *ThingNotificationRepositoryMock) minimockDone() bool {
  314. done := true
  315. return done &&
  316. m.MinimockDeleteDone()
  317. }