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