thing_notification_repository_minimock.go 16 KB

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