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