cache_service_minimock.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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/dmitriygnatenko-v2/internal/services/handler.CacheService -o cache_service_minimock.go -n CacheServiceMock -p mocks
  4. import (
  5. "sync"
  6. mm_atomic "sync/atomic"
  7. "time"
  8. mm_time "time"
  9. "github.com/gojuno/minimock/v3"
  10. )
  11. // CacheServiceMock implements handler.CacheService
  12. type CacheServiceMock struct {
  13. t minimock.Tester
  14. finishOnce sync.Once
  15. funcGet func(key string) (p1 interface{}, b1 bool)
  16. inspectFuncGet func(key string)
  17. afterGetCounter uint64
  18. beforeGetCounter uint64
  19. GetMock mCacheServiceMockGet
  20. funcSet func(key string, value interface{}, expiration *time.Duration)
  21. inspectFuncSet func(key string, value interface{}, expiration *time.Duration)
  22. afterSetCounter uint64
  23. beforeSetCounter uint64
  24. SetMock mCacheServiceMockSet
  25. }
  26. // NewCacheServiceMock returns a mock for handler.CacheService
  27. func NewCacheServiceMock(t minimock.Tester) *CacheServiceMock {
  28. m := &CacheServiceMock{t: t}
  29. if controller, ok := t.(minimock.MockController); ok {
  30. controller.RegisterMocker(m)
  31. }
  32. m.GetMock = mCacheServiceMockGet{mock: m}
  33. m.GetMock.callArgs = []*CacheServiceMockGetParams{}
  34. m.SetMock = mCacheServiceMockSet{mock: m}
  35. m.SetMock.callArgs = []*CacheServiceMockSetParams{}
  36. t.Cleanup(m.MinimockFinish)
  37. return m
  38. }
  39. type mCacheServiceMockGet struct {
  40. optional bool
  41. mock *CacheServiceMock
  42. defaultExpectation *CacheServiceMockGetExpectation
  43. expectations []*CacheServiceMockGetExpectation
  44. callArgs []*CacheServiceMockGetParams
  45. mutex sync.RWMutex
  46. expectedInvocations uint64
  47. }
  48. // CacheServiceMockGetExpectation specifies expectation struct of the CacheService.Get
  49. type CacheServiceMockGetExpectation struct {
  50. mock *CacheServiceMock
  51. params *CacheServiceMockGetParams
  52. paramPtrs *CacheServiceMockGetParamPtrs
  53. results *CacheServiceMockGetResults
  54. Counter uint64
  55. }
  56. // CacheServiceMockGetParams contains parameters of the CacheService.Get
  57. type CacheServiceMockGetParams struct {
  58. key string
  59. }
  60. // CacheServiceMockGetParamPtrs contains pointers to parameters of the CacheService.Get
  61. type CacheServiceMockGetParamPtrs struct {
  62. key *string
  63. }
  64. // CacheServiceMockGetResults contains results of the CacheService.Get
  65. type CacheServiceMockGetResults struct {
  66. p1 interface{}
  67. b1 bool
  68. }
  69. // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
  70. // the test will fail minimock's automatic final call check if the mocked method was not called at least once.
  71. // Optional() makes method check to work in '0 or more' mode.
  72. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
  73. // catch the problems when the expected method call is totally skipped during test run.
  74. func (mmGet *mCacheServiceMockGet) Optional() *mCacheServiceMockGet {
  75. mmGet.optional = true
  76. return mmGet
  77. }
  78. // Expect sets up expected params for CacheService.Get
  79. func (mmGet *mCacheServiceMockGet) Expect(key string) *mCacheServiceMockGet {
  80. if mmGet.mock.funcGet != nil {
  81. mmGet.mock.t.Fatalf("CacheServiceMock.Get mock is already set by Set")
  82. }
  83. if mmGet.defaultExpectation == nil {
  84. mmGet.defaultExpectation = &CacheServiceMockGetExpectation{}
  85. }
  86. if mmGet.defaultExpectation.paramPtrs != nil {
  87. mmGet.mock.t.Fatalf("CacheServiceMock.Get mock is already set by ExpectParams functions")
  88. }
  89. mmGet.defaultExpectation.params = &CacheServiceMockGetParams{key}
  90. for _, e := range mmGet.expectations {
  91. if minimock.Equal(e.params, mmGet.defaultExpectation.params) {
  92. mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params)
  93. }
  94. }
  95. return mmGet
  96. }
  97. // ExpectKeyParam1 sets up expected param key for CacheService.Get
  98. func (mmGet *mCacheServiceMockGet) ExpectKeyParam1(key string) *mCacheServiceMockGet {
  99. if mmGet.mock.funcGet != nil {
  100. mmGet.mock.t.Fatalf("CacheServiceMock.Get mock is already set by Set")
  101. }
  102. if mmGet.defaultExpectation == nil {
  103. mmGet.defaultExpectation = &CacheServiceMockGetExpectation{}
  104. }
  105. if mmGet.defaultExpectation.params != nil {
  106. mmGet.mock.t.Fatalf("CacheServiceMock.Get mock is already set by Expect")
  107. }
  108. if mmGet.defaultExpectation.paramPtrs == nil {
  109. mmGet.defaultExpectation.paramPtrs = &CacheServiceMockGetParamPtrs{}
  110. }
  111. mmGet.defaultExpectation.paramPtrs.key = &key
  112. return mmGet
  113. }
  114. // Inspect accepts an inspector function that has same arguments as the CacheService.Get
  115. func (mmGet *mCacheServiceMockGet) Inspect(f func(key string)) *mCacheServiceMockGet {
  116. if mmGet.mock.inspectFuncGet != nil {
  117. mmGet.mock.t.Fatalf("Inspect function is already set for CacheServiceMock.Get")
  118. }
  119. mmGet.mock.inspectFuncGet = f
  120. return mmGet
  121. }
  122. // Return sets up results that will be returned by CacheService.Get
  123. func (mmGet *mCacheServiceMockGet) Return(p1 interface{}, b1 bool) *CacheServiceMock {
  124. if mmGet.mock.funcGet != nil {
  125. mmGet.mock.t.Fatalf("CacheServiceMock.Get mock is already set by Set")
  126. }
  127. if mmGet.defaultExpectation == nil {
  128. mmGet.defaultExpectation = &CacheServiceMockGetExpectation{mock: mmGet.mock}
  129. }
  130. mmGet.defaultExpectation.results = &CacheServiceMockGetResults{p1, b1}
  131. return mmGet.mock
  132. }
  133. // Set uses given function f to mock the CacheService.Get method
  134. func (mmGet *mCacheServiceMockGet) Set(f func(key string) (p1 interface{}, b1 bool)) *CacheServiceMock {
  135. if mmGet.defaultExpectation != nil {
  136. mmGet.mock.t.Fatalf("Default expectation is already set for the CacheService.Get method")
  137. }
  138. if len(mmGet.expectations) > 0 {
  139. mmGet.mock.t.Fatalf("Some expectations are already set for the CacheService.Get method")
  140. }
  141. mmGet.mock.funcGet = f
  142. return mmGet.mock
  143. }
  144. // When sets expectation for the CacheService.Get which will trigger the result defined by the following
  145. // Then helper
  146. func (mmGet *mCacheServiceMockGet) When(key string) *CacheServiceMockGetExpectation {
  147. if mmGet.mock.funcGet != nil {
  148. mmGet.mock.t.Fatalf("CacheServiceMock.Get mock is already set by Set")
  149. }
  150. expectation := &CacheServiceMockGetExpectation{
  151. mock: mmGet.mock,
  152. params: &CacheServiceMockGetParams{key},
  153. }
  154. mmGet.expectations = append(mmGet.expectations, expectation)
  155. return expectation
  156. }
  157. // Then sets up CacheService.Get return parameters for the expectation previously defined by the When method
  158. func (e *CacheServiceMockGetExpectation) Then(p1 interface{}, b1 bool) *CacheServiceMock {
  159. e.results = &CacheServiceMockGetResults{p1, b1}
  160. return e.mock
  161. }
  162. // Times sets number of times CacheService.Get should be invoked
  163. func (mmGet *mCacheServiceMockGet) Times(n uint64) *mCacheServiceMockGet {
  164. if n == 0 {
  165. mmGet.mock.t.Fatalf("Times of CacheServiceMock.Get mock can not be zero")
  166. }
  167. mm_atomic.StoreUint64(&mmGet.expectedInvocations, n)
  168. return mmGet
  169. }
  170. func (mmGet *mCacheServiceMockGet) invocationsDone() bool {
  171. if len(mmGet.expectations) == 0 && mmGet.defaultExpectation == nil && mmGet.mock.funcGet == nil {
  172. return true
  173. }
  174. totalInvocations := mm_atomic.LoadUint64(&mmGet.mock.afterGetCounter)
  175. expectedInvocations := mm_atomic.LoadUint64(&mmGet.expectedInvocations)
  176. return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
  177. }
  178. // Get implements handler.CacheService
  179. func (mmGet *CacheServiceMock) Get(key string) (p1 interface{}, b1 bool) {
  180. mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1)
  181. defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1)
  182. if mmGet.inspectFuncGet != nil {
  183. mmGet.inspectFuncGet(key)
  184. }
  185. mm_params := CacheServiceMockGetParams{key}
  186. // Record call args
  187. mmGet.GetMock.mutex.Lock()
  188. mmGet.GetMock.callArgs = append(mmGet.GetMock.callArgs, &mm_params)
  189. mmGet.GetMock.mutex.Unlock()
  190. for _, e := range mmGet.GetMock.expectations {
  191. if minimock.Equal(*e.params, mm_params) {
  192. mm_atomic.AddUint64(&e.Counter, 1)
  193. return e.results.p1, e.results.b1
  194. }
  195. }
  196. if mmGet.GetMock.defaultExpectation != nil {
  197. mm_atomic.AddUint64(&mmGet.GetMock.defaultExpectation.Counter, 1)
  198. mm_want := mmGet.GetMock.defaultExpectation.params
  199. mm_want_ptrs := mmGet.GetMock.defaultExpectation.paramPtrs
  200. mm_got := CacheServiceMockGetParams{key}
  201. if mm_want_ptrs != nil {
  202. if mm_want_ptrs.key != nil && !minimock.Equal(*mm_want_ptrs.key, mm_got.key) {
  203. mmGet.t.Errorf("CacheServiceMock.Get got unexpected parameter key, want: %#v, got: %#v%s\n", *mm_want_ptrs.key, mm_got.key, minimock.Diff(*mm_want_ptrs.key, mm_got.key))
  204. }
  205. } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  206. mmGet.t.Errorf("CacheServiceMock.Get got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  207. }
  208. mm_results := mmGet.GetMock.defaultExpectation.results
  209. if mm_results == nil {
  210. mmGet.t.Fatal("No results are set for the CacheServiceMock.Get")
  211. }
  212. return (*mm_results).p1, (*mm_results).b1
  213. }
  214. if mmGet.funcGet != nil {
  215. return mmGet.funcGet(key)
  216. }
  217. mmGet.t.Fatalf("Unexpected call to CacheServiceMock.Get. %v", key)
  218. return
  219. }
  220. // GetAfterCounter returns a count of finished CacheServiceMock.Get invocations
  221. func (mmGet *CacheServiceMock) GetAfterCounter() uint64 {
  222. return mm_atomic.LoadUint64(&mmGet.afterGetCounter)
  223. }
  224. // GetBeforeCounter returns a count of CacheServiceMock.Get invocations
  225. func (mmGet *CacheServiceMock) GetBeforeCounter() uint64 {
  226. return mm_atomic.LoadUint64(&mmGet.beforeGetCounter)
  227. }
  228. // Calls returns a list of arguments used in each call to CacheServiceMock.Get.
  229. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  230. func (mmGet *mCacheServiceMockGet) Calls() []*CacheServiceMockGetParams {
  231. mmGet.mutex.RLock()
  232. argCopy := make([]*CacheServiceMockGetParams, len(mmGet.callArgs))
  233. copy(argCopy, mmGet.callArgs)
  234. mmGet.mutex.RUnlock()
  235. return argCopy
  236. }
  237. // MinimockGetDone returns true if the count of the Get invocations corresponds
  238. // the number of defined expectations
  239. func (m *CacheServiceMock) MinimockGetDone() bool {
  240. if m.GetMock.optional {
  241. // Optional methods provide '0 or more' call count restriction.
  242. return true
  243. }
  244. for _, e := range m.GetMock.expectations {
  245. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  246. return false
  247. }
  248. }
  249. return m.GetMock.invocationsDone()
  250. }
  251. // MinimockGetInspect logs each unmet expectation
  252. func (m *CacheServiceMock) MinimockGetInspect() {
  253. for _, e := range m.GetMock.expectations {
  254. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  255. m.t.Errorf("Expected call to CacheServiceMock.Get with params: %#v", *e.params)
  256. }
  257. }
  258. afterGetCounter := mm_atomic.LoadUint64(&m.afterGetCounter)
  259. // if default expectation was set then invocations count should be greater than zero
  260. if m.GetMock.defaultExpectation != nil && afterGetCounter < 1 {
  261. if m.GetMock.defaultExpectation.params == nil {
  262. m.t.Error("Expected call to CacheServiceMock.Get")
  263. } else {
  264. m.t.Errorf("Expected call to CacheServiceMock.Get with params: %#v", *m.GetMock.defaultExpectation.params)
  265. }
  266. }
  267. // if func was set then invocations count should be greater than zero
  268. if m.funcGet != nil && afterGetCounter < 1 {
  269. m.t.Error("Expected call to CacheServiceMock.Get")
  270. }
  271. if !m.GetMock.invocationsDone() && afterGetCounter > 0 {
  272. m.t.Errorf("Expected %d calls to CacheServiceMock.Get but found %d calls",
  273. mm_atomic.LoadUint64(&m.GetMock.expectedInvocations), afterGetCounter)
  274. }
  275. }
  276. type mCacheServiceMockSet struct {
  277. optional bool
  278. mock *CacheServiceMock
  279. defaultExpectation *CacheServiceMockSetExpectation
  280. expectations []*CacheServiceMockSetExpectation
  281. callArgs []*CacheServiceMockSetParams
  282. mutex sync.RWMutex
  283. expectedInvocations uint64
  284. }
  285. // CacheServiceMockSetExpectation specifies expectation struct of the CacheService.Set
  286. type CacheServiceMockSetExpectation struct {
  287. mock *CacheServiceMock
  288. params *CacheServiceMockSetParams
  289. paramPtrs *CacheServiceMockSetParamPtrs
  290. Counter uint64
  291. }
  292. // CacheServiceMockSetParams contains parameters of the CacheService.Set
  293. type CacheServiceMockSetParams struct {
  294. key string
  295. value interface{}
  296. expiration *time.Duration
  297. }
  298. // CacheServiceMockSetParamPtrs contains pointers to parameters of the CacheService.Set
  299. type CacheServiceMockSetParamPtrs struct {
  300. key *string
  301. value *interface{}
  302. expiration **time.Duration
  303. }
  304. // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
  305. // the test will fail minimock's automatic final call check if the mocked method was not called at least once.
  306. // Optional() makes method check to work in '0 or more' mode.
  307. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
  308. // catch the problems when the expected method call is totally skipped during test run.
  309. func (mmSet *mCacheServiceMockSet) Optional() *mCacheServiceMockSet {
  310. mmSet.optional = true
  311. return mmSet
  312. }
  313. // Expect sets up expected params for CacheService.Set
  314. func (mmSet *mCacheServiceMockSet) Expect(key string, value interface{}, expiration *time.Duration) *mCacheServiceMockSet {
  315. if mmSet.mock.funcSet != nil {
  316. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by Set")
  317. }
  318. if mmSet.defaultExpectation == nil {
  319. mmSet.defaultExpectation = &CacheServiceMockSetExpectation{}
  320. }
  321. if mmSet.defaultExpectation.paramPtrs != nil {
  322. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by ExpectParams functions")
  323. }
  324. mmSet.defaultExpectation.params = &CacheServiceMockSetParams{key, value, expiration}
  325. for _, e := range mmSet.expectations {
  326. if minimock.Equal(e.params, mmSet.defaultExpectation.params) {
  327. mmSet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmSet.defaultExpectation.params)
  328. }
  329. }
  330. return mmSet
  331. }
  332. // ExpectKeyParam1 sets up expected param key for CacheService.Set
  333. func (mmSet *mCacheServiceMockSet) ExpectKeyParam1(key string) *mCacheServiceMockSet {
  334. if mmSet.mock.funcSet != nil {
  335. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by Set")
  336. }
  337. if mmSet.defaultExpectation == nil {
  338. mmSet.defaultExpectation = &CacheServiceMockSetExpectation{}
  339. }
  340. if mmSet.defaultExpectation.params != nil {
  341. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by Expect")
  342. }
  343. if mmSet.defaultExpectation.paramPtrs == nil {
  344. mmSet.defaultExpectation.paramPtrs = &CacheServiceMockSetParamPtrs{}
  345. }
  346. mmSet.defaultExpectation.paramPtrs.key = &key
  347. return mmSet
  348. }
  349. // ExpectValueParam2 sets up expected param value for CacheService.Set
  350. func (mmSet *mCacheServiceMockSet) ExpectValueParam2(value interface{}) *mCacheServiceMockSet {
  351. if mmSet.mock.funcSet != nil {
  352. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by Set")
  353. }
  354. if mmSet.defaultExpectation == nil {
  355. mmSet.defaultExpectation = &CacheServiceMockSetExpectation{}
  356. }
  357. if mmSet.defaultExpectation.params != nil {
  358. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by Expect")
  359. }
  360. if mmSet.defaultExpectation.paramPtrs == nil {
  361. mmSet.defaultExpectation.paramPtrs = &CacheServiceMockSetParamPtrs{}
  362. }
  363. mmSet.defaultExpectation.paramPtrs.value = &value
  364. return mmSet
  365. }
  366. // ExpectExpirationParam3 sets up expected param expiration for CacheService.Set
  367. func (mmSet *mCacheServiceMockSet) ExpectExpirationParam3(expiration *time.Duration) *mCacheServiceMockSet {
  368. if mmSet.mock.funcSet != nil {
  369. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by Set")
  370. }
  371. if mmSet.defaultExpectation == nil {
  372. mmSet.defaultExpectation = &CacheServiceMockSetExpectation{}
  373. }
  374. if mmSet.defaultExpectation.params != nil {
  375. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by Expect")
  376. }
  377. if mmSet.defaultExpectation.paramPtrs == nil {
  378. mmSet.defaultExpectation.paramPtrs = &CacheServiceMockSetParamPtrs{}
  379. }
  380. mmSet.defaultExpectation.paramPtrs.expiration = &expiration
  381. return mmSet
  382. }
  383. // Inspect accepts an inspector function that has same arguments as the CacheService.Set
  384. func (mmSet *mCacheServiceMockSet) Inspect(f func(key string, value interface{}, expiration *time.Duration)) *mCacheServiceMockSet {
  385. if mmSet.mock.inspectFuncSet != nil {
  386. mmSet.mock.t.Fatalf("Inspect function is already set for CacheServiceMock.Set")
  387. }
  388. mmSet.mock.inspectFuncSet = f
  389. return mmSet
  390. }
  391. // Return sets up results that will be returned by CacheService.Set
  392. func (mmSet *mCacheServiceMockSet) Return() *CacheServiceMock {
  393. if mmSet.mock.funcSet != nil {
  394. mmSet.mock.t.Fatalf("CacheServiceMock.Set mock is already set by Set")
  395. }
  396. if mmSet.defaultExpectation == nil {
  397. mmSet.defaultExpectation = &CacheServiceMockSetExpectation{mock: mmSet.mock}
  398. }
  399. return mmSet.mock
  400. }
  401. // Set uses given function f to mock the CacheService.Set method
  402. func (mmSet *mCacheServiceMockSet) Set(f func(key string, value interface{}, expiration *time.Duration)) *CacheServiceMock {
  403. if mmSet.defaultExpectation != nil {
  404. mmSet.mock.t.Fatalf("Default expectation is already set for the CacheService.Set method")
  405. }
  406. if len(mmSet.expectations) > 0 {
  407. mmSet.mock.t.Fatalf("Some expectations are already set for the CacheService.Set method")
  408. }
  409. mmSet.mock.funcSet = f
  410. return mmSet.mock
  411. }
  412. // Times sets number of times CacheService.Set should be invoked
  413. func (mmSet *mCacheServiceMockSet) Times(n uint64) *mCacheServiceMockSet {
  414. if n == 0 {
  415. mmSet.mock.t.Fatalf("Times of CacheServiceMock.Set mock can not be zero")
  416. }
  417. mm_atomic.StoreUint64(&mmSet.expectedInvocations, n)
  418. return mmSet
  419. }
  420. func (mmSet *mCacheServiceMockSet) invocationsDone() bool {
  421. if len(mmSet.expectations) == 0 && mmSet.defaultExpectation == nil && mmSet.mock.funcSet == nil {
  422. return true
  423. }
  424. totalInvocations := mm_atomic.LoadUint64(&mmSet.mock.afterSetCounter)
  425. expectedInvocations := mm_atomic.LoadUint64(&mmSet.expectedInvocations)
  426. return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
  427. }
  428. // Set implements handler.CacheService
  429. func (mmSet *CacheServiceMock) Set(key string, value interface{}, expiration *time.Duration) {
  430. mm_atomic.AddUint64(&mmSet.beforeSetCounter, 1)
  431. defer mm_atomic.AddUint64(&mmSet.afterSetCounter, 1)
  432. if mmSet.inspectFuncSet != nil {
  433. mmSet.inspectFuncSet(key, value, expiration)
  434. }
  435. mm_params := CacheServiceMockSetParams{key, value, expiration}
  436. // Record call args
  437. mmSet.SetMock.mutex.Lock()
  438. mmSet.SetMock.callArgs = append(mmSet.SetMock.callArgs, &mm_params)
  439. mmSet.SetMock.mutex.Unlock()
  440. for _, e := range mmSet.SetMock.expectations {
  441. if minimock.Equal(*e.params, mm_params) {
  442. mm_atomic.AddUint64(&e.Counter, 1)
  443. return
  444. }
  445. }
  446. if mmSet.SetMock.defaultExpectation != nil {
  447. mm_atomic.AddUint64(&mmSet.SetMock.defaultExpectation.Counter, 1)
  448. mm_want := mmSet.SetMock.defaultExpectation.params
  449. mm_want_ptrs := mmSet.SetMock.defaultExpectation.paramPtrs
  450. mm_got := CacheServiceMockSetParams{key, value, expiration}
  451. if mm_want_ptrs != nil {
  452. if mm_want_ptrs.key != nil && !minimock.Equal(*mm_want_ptrs.key, mm_got.key) {
  453. mmSet.t.Errorf("CacheServiceMock.Set got unexpected parameter key, want: %#v, got: %#v%s\n", *mm_want_ptrs.key, mm_got.key, minimock.Diff(*mm_want_ptrs.key, mm_got.key))
  454. }
  455. if mm_want_ptrs.value != nil && !minimock.Equal(*mm_want_ptrs.value, mm_got.value) {
  456. mmSet.t.Errorf("CacheServiceMock.Set got unexpected parameter value, want: %#v, got: %#v%s\n", *mm_want_ptrs.value, mm_got.value, minimock.Diff(*mm_want_ptrs.value, mm_got.value))
  457. }
  458. if mm_want_ptrs.expiration != nil && !minimock.Equal(*mm_want_ptrs.expiration, mm_got.expiration) {
  459. mmSet.t.Errorf("CacheServiceMock.Set got unexpected parameter expiration, want: %#v, got: %#v%s\n", *mm_want_ptrs.expiration, mm_got.expiration, minimock.Diff(*mm_want_ptrs.expiration, mm_got.expiration))
  460. }
  461. } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  462. mmSet.t.Errorf("CacheServiceMock.Set got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  463. }
  464. return
  465. }
  466. if mmSet.funcSet != nil {
  467. mmSet.funcSet(key, value, expiration)
  468. return
  469. }
  470. mmSet.t.Fatalf("Unexpected call to CacheServiceMock.Set. %v %v %v", key, value, expiration)
  471. }
  472. // SetAfterCounter returns a count of finished CacheServiceMock.Set invocations
  473. func (mmSet *CacheServiceMock) SetAfterCounter() uint64 {
  474. return mm_atomic.LoadUint64(&mmSet.afterSetCounter)
  475. }
  476. // SetBeforeCounter returns a count of CacheServiceMock.Set invocations
  477. func (mmSet *CacheServiceMock) SetBeforeCounter() uint64 {
  478. return mm_atomic.LoadUint64(&mmSet.beforeSetCounter)
  479. }
  480. // Calls returns a list of arguments used in each call to CacheServiceMock.Set.
  481. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  482. func (mmSet *mCacheServiceMockSet) Calls() []*CacheServiceMockSetParams {
  483. mmSet.mutex.RLock()
  484. argCopy := make([]*CacheServiceMockSetParams, len(mmSet.callArgs))
  485. copy(argCopy, mmSet.callArgs)
  486. mmSet.mutex.RUnlock()
  487. return argCopy
  488. }
  489. // MinimockSetDone returns true if the count of the Set invocations corresponds
  490. // the number of defined expectations
  491. func (m *CacheServiceMock) MinimockSetDone() bool {
  492. if m.SetMock.optional {
  493. // Optional methods provide '0 or more' call count restriction.
  494. return true
  495. }
  496. for _, e := range m.SetMock.expectations {
  497. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  498. return false
  499. }
  500. }
  501. return m.SetMock.invocationsDone()
  502. }
  503. // MinimockSetInspect logs each unmet expectation
  504. func (m *CacheServiceMock) MinimockSetInspect() {
  505. for _, e := range m.SetMock.expectations {
  506. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  507. m.t.Errorf("Expected call to CacheServiceMock.Set with params: %#v", *e.params)
  508. }
  509. }
  510. afterSetCounter := mm_atomic.LoadUint64(&m.afterSetCounter)
  511. // if default expectation was set then invocations count should be greater than zero
  512. if m.SetMock.defaultExpectation != nil && afterSetCounter < 1 {
  513. if m.SetMock.defaultExpectation.params == nil {
  514. m.t.Error("Expected call to CacheServiceMock.Set")
  515. } else {
  516. m.t.Errorf("Expected call to CacheServiceMock.Set with params: %#v", *m.SetMock.defaultExpectation.params)
  517. }
  518. }
  519. // if func was set then invocations count should be greater than zero
  520. if m.funcSet != nil && afterSetCounter < 1 {
  521. m.t.Error("Expected call to CacheServiceMock.Set")
  522. }
  523. if !m.SetMock.invocationsDone() && afterSetCounter > 0 {
  524. m.t.Errorf("Expected %d calls to CacheServiceMock.Set but found %d calls",
  525. mm_atomic.LoadUint64(&m.SetMock.expectedInvocations), afterSetCounter)
  526. }
  527. }
  528. // MinimockFinish checks that all mocked methods have been called the expected number of times
  529. func (m *CacheServiceMock) MinimockFinish() {
  530. m.finishOnce.Do(func() {
  531. if !m.minimockDone() {
  532. m.MinimockGetInspect()
  533. m.MinimockSetInspect()
  534. }
  535. })
  536. }
  537. // MinimockWait waits for all mocked methods to be called the expected number of times
  538. func (m *CacheServiceMock) MinimockWait(timeout mm_time.Duration) {
  539. timeoutCh := mm_time.After(timeout)
  540. for {
  541. if m.minimockDone() {
  542. return
  543. }
  544. select {
  545. case <-timeoutCh:
  546. m.MinimockFinish()
  547. return
  548. case <-mm_time.After(10 * mm_time.Millisecond):
  549. }
  550. }
  551. }
  552. func (m *CacheServiceMock) minimockDone() bool {
  553. done := true
  554. return done &&
  555. m.MinimockGetDone() &&
  556. m.MinimockSetDone()
  557. }