user_repository_minimock.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. package mocks
  2. // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT.
  3. //go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/interfaces.UserRepository -o ./mocks/user_repository_minimock.go -n UserRepositoryMock
  4. import (
  5. "context"
  6. "sync"
  7. mm_atomic "sync/atomic"
  8. mm_time "time"
  9. "git.dmitriygnatenko.ru/dima/homethings/internal/models"
  10. "github.com/gojuno/minimock/v3"
  11. )
  12. // UserRepositoryMock implements interfaces.UserRepository
  13. type UserRepositoryMock struct {
  14. t minimock.Tester
  15. funcAdd func(ctx context.Context, username string, password string) (i1 int, err error)
  16. inspectFuncAdd func(ctx context.Context, username string, password string)
  17. afterAddCounter uint64
  18. beforeAddCounter uint64
  19. AddMock mUserRepositoryMockAdd
  20. funcGet func(ctx context.Context, username string) (up1 *models.User, err error)
  21. inspectFuncGet func(ctx context.Context, username string)
  22. afterGetCounter uint64
  23. beforeGetCounter uint64
  24. GetMock mUserRepositoryMockGet
  25. funcUpdate func(ctx context.Context, req models.UpdateUserRequest) (err error)
  26. inspectFuncUpdate func(ctx context.Context, req models.UpdateUserRequest)
  27. afterUpdateCounter uint64
  28. beforeUpdateCounter uint64
  29. UpdateMock mUserRepositoryMockUpdate
  30. }
  31. // NewUserRepositoryMock returns a mock for interfaces.UserRepository
  32. func NewUserRepositoryMock(t minimock.Tester) *UserRepositoryMock {
  33. m := &UserRepositoryMock{t: t}
  34. if controller, ok := t.(minimock.MockController); ok {
  35. controller.RegisterMocker(m)
  36. }
  37. m.AddMock = mUserRepositoryMockAdd{mock: m}
  38. m.AddMock.callArgs = []*UserRepositoryMockAddParams{}
  39. m.GetMock = mUserRepositoryMockGet{mock: m}
  40. m.GetMock.callArgs = []*UserRepositoryMockGetParams{}
  41. m.UpdateMock = mUserRepositoryMockUpdate{mock: m}
  42. m.UpdateMock.callArgs = []*UserRepositoryMockUpdateParams{}
  43. return m
  44. }
  45. type mUserRepositoryMockAdd struct {
  46. mock *UserRepositoryMock
  47. defaultExpectation *UserRepositoryMockAddExpectation
  48. expectations []*UserRepositoryMockAddExpectation
  49. callArgs []*UserRepositoryMockAddParams
  50. mutex sync.RWMutex
  51. }
  52. // UserRepositoryMockAddExpectation specifies expectation struct of the UserRepository.Add
  53. type UserRepositoryMockAddExpectation struct {
  54. mock *UserRepositoryMock
  55. params *UserRepositoryMockAddParams
  56. results *UserRepositoryMockAddResults
  57. Counter uint64
  58. }
  59. // UserRepositoryMockAddParams contains parameters of the UserRepository.Add
  60. type UserRepositoryMockAddParams struct {
  61. ctx context.Context
  62. username string
  63. password string
  64. }
  65. // UserRepositoryMockAddResults contains results of the UserRepository.Add
  66. type UserRepositoryMockAddResults struct {
  67. i1 int
  68. err error
  69. }
  70. // Expect sets up expected params for UserRepository.Add
  71. func (mmAdd *mUserRepositoryMockAdd) Expect(ctx context.Context, username string, password string) *mUserRepositoryMockAdd {
  72. if mmAdd.mock.funcAdd != nil {
  73. mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set")
  74. }
  75. if mmAdd.defaultExpectation == nil {
  76. mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{}
  77. }
  78. mmAdd.defaultExpectation.params = &UserRepositoryMockAddParams{ctx, username, password}
  79. for _, e := range mmAdd.expectations {
  80. if minimock.Equal(e.params, mmAdd.defaultExpectation.params) {
  81. mmAdd.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmAdd.defaultExpectation.params)
  82. }
  83. }
  84. return mmAdd
  85. }
  86. // Inspect accepts an inspector function that has same arguments as the UserRepository.Add
  87. func (mmAdd *mUserRepositoryMockAdd) Inspect(f func(ctx context.Context, username string, password string)) *mUserRepositoryMockAdd {
  88. if mmAdd.mock.inspectFuncAdd != nil {
  89. mmAdd.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Add")
  90. }
  91. mmAdd.mock.inspectFuncAdd = f
  92. return mmAdd
  93. }
  94. // Return sets up results that will be returned by UserRepository.Add
  95. func (mmAdd *mUserRepositoryMockAdd) Return(i1 int, err error) *UserRepositoryMock {
  96. if mmAdd.mock.funcAdd != nil {
  97. mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set")
  98. }
  99. if mmAdd.defaultExpectation == nil {
  100. mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{mock: mmAdd.mock}
  101. }
  102. mmAdd.defaultExpectation.results = &UserRepositoryMockAddResults{i1, err}
  103. return mmAdd.mock
  104. }
  105. // Set uses given function f to mock the UserRepository.Add method
  106. func (mmAdd *mUserRepositoryMockAdd) Set(f func(ctx context.Context, username string, password string) (i1 int, err error)) *UserRepositoryMock {
  107. if mmAdd.defaultExpectation != nil {
  108. mmAdd.mock.t.Fatalf("Default expectation is already set for the UserRepository.Add method")
  109. }
  110. if len(mmAdd.expectations) > 0 {
  111. mmAdd.mock.t.Fatalf("Some expectations are already set for the UserRepository.Add method")
  112. }
  113. mmAdd.mock.funcAdd = f
  114. return mmAdd.mock
  115. }
  116. // When sets expectation for the UserRepository.Add which will trigger the result defined by the following
  117. // Then helper
  118. func (mmAdd *mUserRepositoryMockAdd) When(ctx context.Context, username string, password string) *UserRepositoryMockAddExpectation {
  119. if mmAdd.mock.funcAdd != nil {
  120. mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set")
  121. }
  122. expectation := &UserRepositoryMockAddExpectation{
  123. mock: mmAdd.mock,
  124. params: &UserRepositoryMockAddParams{ctx, username, password},
  125. }
  126. mmAdd.expectations = append(mmAdd.expectations, expectation)
  127. return expectation
  128. }
  129. // Then sets up UserRepository.Add return parameters for the expectation previously defined by the When method
  130. func (e *UserRepositoryMockAddExpectation) Then(i1 int, err error) *UserRepositoryMock {
  131. e.results = &UserRepositoryMockAddResults{i1, err}
  132. return e.mock
  133. }
  134. // Add implements interfaces.UserRepository
  135. func (mmAdd *UserRepositoryMock) Add(ctx context.Context, username string, password string) (i1 int, err error) {
  136. mm_atomic.AddUint64(&mmAdd.beforeAddCounter, 1)
  137. defer mm_atomic.AddUint64(&mmAdd.afterAddCounter, 1)
  138. if mmAdd.inspectFuncAdd != nil {
  139. mmAdd.inspectFuncAdd(ctx, username, password)
  140. }
  141. mm_params := &UserRepositoryMockAddParams{ctx, username, password}
  142. // Record call args
  143. mmAdd.AddMock.mutex.Lock()
  144. mmAdd.AddMock.callArgs = append(mmAdd.AddMock.callArgs, mm_params)
  145. mmAdd.AddMock.mutex.Unlock()
  146. for _, e := range mmAdd.AddMock.expectations {
  147. if minimock.Equal(e.params, mm_params) {
  148. mm_atomic.AddUint64(&e.Counter, 1)
  149. return e.results.i1, e.results.err
  150. }
  151. }
  152. if mmAdd.AddMock.defaultExpectation != nil {
  153. mm_atomic.AddUint64(&mmAdd.AddMock.defaultExpectation.Counter, 1)
  154. mm_want := mmAdd.AddMock.defaultExpectation.params
  155. mm_got := UserRepositoryMockAddParams{ctx, username, password}
  156. if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  157. mmAdd.t.Errorf("UserRepositoryMock.Add got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  158. }
  159. mm_results := mmAdd.AddMock.defaultExpectation.results
  160. if mm_results == nil {
  161. mmAdd.t.Fatal("No results are set for the UserRepositoryMock.Add")
  162. }
  163. return (*mm_results).i1, (*mm_results).err
  164. }
  165. if mmAdd.funcAdd != nil {
  166. return mmAdd.funcAdd(ctx, username, password)
  167. }
  168. mmAdd.t.Fatalf("Unexpected call to UserRepositoryMock.Add. %v %v %v", ctx, username, password)
  169. return
  170. }
  171. // AddAfterCounter returns a count of finished UserRepositoryMock.Add invocations
  172. func (mmAdd *UserRepositoryMock) AddAfterCounter() uint64 {
  173. return mm_atomic.LoadUint64(&mmAdd.afterAddCounter)
  174. }
  175. // AddBeforeCounter returns a count of UserRepositoryMock.Add invocations
  176. func (mmAdd *UserRepositoryMock) AddBeforeCounter() uint64 {
  177. return mm_atomic.LoadUint64(&mmAdd.beforeAddCounter)
  178. }
  179. // Calls returns a list of arguments used in each call to UserRepositoryMock.Add.
  180. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  181. func (mmAdd *mUserRepositoryMockAdd) Calls() []*UserRepositoryMockAddParams {
  182. mmAdd.mutex.RLock()
  183. argCopy := make([]*UserRepositoryMockAddParams, len(mmAdd.callArgs))
  184. copy(argCopy, mmAdd.callArgs)
  185. mmAdd.mutex.RUnlock()
  186. return argCopy
  187. }
  188. // MinimockAddDone returns true if the count of the Add invocations corresponds
  189. // the number of defined expectations
  190. func (m *UserRepositoryMock) MinimockAddDone() bool {
  191. for _, e := range m.AddMock.expectations {
  192. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  193. return false
  194. }
  195. }
  196. // if default expectation was set then invocations count should be greater than zero
  197. if m.AddMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterAddCounter) < 1 {
  198. return false
  199. }
  200. // if func was set then invocations count should be greater than zero
  201. if m.funcAdd != nil && mm_atomic.LoadUint64(&m.afterAddCounter) < 1 {
  202. return false
  203. }
  204. return true
  205. }
  206. // MinimockAddInspect logs each unmet expectation
  207. func (m *UserRepositoryMock) MinimockAddInspect() {
  208. for _, e := range m.AddMock.expectations {
  209. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  210. m.t.Errorf("Expected call to UserRepositoryMock.Add with params: %#v", *e.params)
  211. }
  212. }
  213. // if default expectation was set then invocations count should be greater than zero
  214. if m.AddMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterAddCounter) < 1 {
  215. if m.AddMock.defaultExpectation.params == nil {
  216. m.t.Error("Expected call to UserRepositoryMock.Add")
  217. } else {
  218. m.t.Errorf("Expected call to UserRepositoryMock.Add with params: %#v", *m.AddMock.defaultExpectation.params)
  219. }
  220. }
  221. // if func was set then invocations count should be greater than zero
  222. if m.funcAdd != nil && mm_atomic.LoadUint64(&m.afterAddCounter) < 1 {
  223. m.t.Error("Expected call to UserRepositoryMock.Add")
  224. }
  225. }
  226. type mUserRepositoryMockGet struct {
  227. mock *UserRepositoryMock
  228. defaultExpectation *UserRepositoryMockGetExpectation
  229. expectations []*UserRepositoryMockGetExpectation
  230. callArgs []*UserRepositoryMockGetParams
  231. mutex sync.RWMutex
  232. }
  233. // UserRepositoryMockGetExpectation specifies expectation struct of the UserRepository.Get
  234. type UserRepositoryMockGetExpectation struct {
  235. mock *UserRepositoryMock
  236. params *UserRepositoryMockGetParams
  237. results *UserRepositoryMockGetResults
  238. Counter uint64
  239. }
  240. // UserRepositoryMockGetParams contains parameters of the UserRepository.Get
  241. type UserRepositoryMockGetParams struct {
  242. ctx context.Context
  243. username string
  244. }
  245. // UserRepositoryMockGetResults contains results of the UserRepository.Get
  246. type UserRepositoryMockGetResults struct {
  247. up1 *models.User
  248. err error
  249. }
  250. // Expect sets up expected params for UserRepository.Get
  251. func (mmGet *mUserRepositoryMockGet) Expect(ctx context.Context, username string) *mUserRepositoryMockGet {
  252. if mmGet.mock.funcGet != nil {
  253. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  254. }
  255. if mmGet.defaultExpectation == nil {
  256. mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{}
  257. }
  258. mmGet.defaultExpectation.params = &UserRepositoryMockGetParams{ctx, username}
  259. for _, e := range mmGet.expectations {
  260. if minimock.Equal(e.params, mmGet.defaultExpectation.params) {
  261. mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params)
  262. }
  263. }
  264. return mmGet
  265. }
  266. // Inspect accepts an inspector function that has same arguments as the UserRepository.Get
  267. func (mmGet *mUserRepositoryMockGet) Inspect(f func(ctx context.Context, username string)) *mUserRepositoryMockGet {
  268. if mmGet.mock.inspectFuncGet != nil {
  269. mmGet.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Get")
  270. }
  271. mmGet.mock.inspectFuncGet = f
  272. return mmGet
  273. }
  274. // Return sets up results that will be returned by UserRepository.Get
  275. func (mmGet *mUserRepositoryMockGet) Return(up1 *models.User, err error) *UserRepositoryMock {
  276. if mmGet.mock.funcGet != nil {
  277. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  278. }
  279. if mmGet.defaultExpectation == nil {
  280. mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{mock: mmGet.mock}
  281. }
  282. mmGet.defaultExpectation.results = &UserRepositoryMockGetResults{up1, err}
  283. return mmGet.mock
  284. }
  285. // Set uses given function f to mock the UserRepository.Get method
  286. func (mmGet *mUserRepositoryMockGet) Set(f func(ctx context.Context, username string) (up1 *models.User, err error)) *UserRepositoryMock {
  287. if mmGet.defaultExpectation != nil {
  288. mmGet.mock.t.Fatalf("Default expectation is already set for the UserRepository.Get method")
  289. }
  290. if len(mmGet.expectations) > 0 {
  291. mmGet.mock.t.Fatalf("Some expectations are already set for the UserRepository.Get method")
  292. }
  293. mmGet.mock.funcGet = f
  294. return mmGet.mock
  295. }
  296. // When sets expectation for the UserRepository.Get which will trigger the result defined by the following
  297. // Then helper
  298. func (mmGet *mUserRepositoryMockGet) When(ctx context.Context, username string) *UserRepositoryMockGetExpectation {
  299. if mmGet.mock.funcGet != nil {
  300. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  301. }
  302. expectation := &UserRepositoryMockGetExpectation{
  303. mock: mmGet.mock,
  304. params: &UserRepositoryMockGetParams{ctx, username},
  305. }
  306. mmGet.expectations = append(mmGet.expectations, expectation)
  307. return expectation
  308. }
  309. // Then sets up UserRepository.Get return parameters for the expectation previously defined by the When method
  310. func (e *UserRepositoryMockGetExpectation) Then(up1 *models.User, err error) *UserRepositoryMock {
  311. e.results = &UserRepositoryMockGetResults{up1, err}
  312. return e.mock
  313. }
  314. // Get implements interfaces.UserRepository
  315. func (mmGet *UserRepositoryMock) Get(ctx context.Context, username string) (up1 *models.User, err error) {
  316. mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1)
  317. defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1)
  318. if mmGet.inspectFuncGet != nil {
  319. mmGet.inspectFuncGet(ctx, username)
  320. }
  321. mm_params := &UserRepositoryMockGetParams{ctx, username}
  322. // Record call args
  323. mmGet.GetMock.mutex.Lock()
  324. mmGet.GetMock.callArgs = append(mmGet.GetMock.callArgs, mm_params)
  325. mmGet.GetMock.mutex.Unlock()
  326. for _, e := range mmGet.GetMock.expectations {
  327. if minimock.Equal(e.params, mm_params) {
  328. mm_atomic.AddUint64(&e.Counter, 1)
  329. return e.results.up1, e.results.err
  330. }
  331. }
  332. if mmGet.GetMock.defaultExpectation != nil {
  333. mm_atomic.AddUint64(&mmGet.GetMock.defaultExpectation.Counter, 1)
  334. mm_want := mmGet.GetMock.defaultExpectation.params
  335. mm_got := UserRepositoryMockGetParams{ctx, username}
  336. if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  337. mmGet.t.Errorf("UserRepositoryMock.Get got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  338. }
  339. mm_results := mmGet.GetMock.defaultExpectation.results
  340. if mm_results == nil {
  341. mmGet.t.Fatal("No results are set for the UserRepositoryMock.Get")
  342. }
  343. return (*mm_results).up1, (*mm_results).err
  344. }
  345. if mmGet.funcGet != nil {
  346. return mmGet.funcGet(ctx, username)
  347. }
  348. mmGet.t.Fatalf("Unexpected call to UserRepositoryMock.Get. %v %v", ctx, username)
  349. return
  350. }
  351. // GetAfterCounter returns a count of finished UserRepositoryMock.Get invocations
  352. func (mmGet *UserRepositoryMock) GetAfterCounter() uint64 {
  353. return mm_atomic.LoadUint64(&mmGet.afterGetCounter)
  354. }
  355. // GetBeforeCounter returns a count of UserRepositoryMock.Get invocations
  356. func (mmGet *UserRepositoryMock) GetBeforeCounter() uint64 {
  357. return mm_atomic.LoadUint64(&mmGet.beforeGetCounter)
  358. }
  359. // Calls returns a list of arguments used in each call to UserRepositoryMock.Get.
  360. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  361. func (mmGet *mUserRepositoryMockGet) Calls() []*UserRepositoryMockGetParams {
  362. mmGet.mutex.RLock()
  363. argCopy := make([]*UserRepositoryMockGetParams, len(mmGet.callArgs))
  364. copy(argCopy, mmGet.callArgs)
  365. mmGet.mutex.RUnlock()
  366. return argCopy
  367. }
  368. // MinimockGetDone returns true if the count of the Get invocations corresponds
  369. // the number of defined expectations
  370. func (m *UserRepositoryMock) MinimockGetDone() bool {
  371. for _, e := range m.GetMock.expectations {
  372. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  373. return false
  374. }
  375. }
  376. // if default expectation was set then invocations count should be greater than zero
  377. if m.GetMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 {
  378. return false
  379. }
  380. // if func was set then invocations count should be greater than zero
  381. if m.funcGet != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 {
  382. return false
  383. }
  384. return true
  385. }
  386. // MinimockGetInspect logs each unmet expectation
  387. func (m *UserRepositoryMock) MinimockGetInspect() {
  388. for _, e := range m.GetMock.expectations {
  389. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  390. m.t.Errorf("Expected call to UserRepositoryMock.Get with params: %#v", *e.params)
  391. }
  392. }
  393. // if default expectation was set then invocations count should be greater than zero
  394. if m.GetMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 {
  395. if m.GetMock.defaultExpectation.params == nil {
  396. m.t.Error("Expected call to UserRepositoryMock.Get")
  397. } else {
  398. m.t.Errorf("Expected call to UserRepositoryMock.Get with params: %#v", *m.GetMock.defaultExpectation.params)
  399. }
  400. }
  401. // if func was set then invocations count should be greater than zero
  402. if m.funcGet != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 {
  403. m.t.Error("Expected call to UserRepositoryMock.Get")
  404. }
  405. }
  406. type mUserRepositoryMockUpdate struct {
  407. mock *UserRepositoryMock
  408. defaultExpectation *UserRepositoryMockUpdateExpectation
  409. expectations []*UserRepositoryMockUpdateExpectation
  410. callArgs []*UserRepositoryMockUpdateParams
  411. mutex sync.RWMutex
  412. }
  413. // UserRepositoryMockUpdateExpectation specifies expectation struct of the UserRepository.Update
  414. type UserRepositoryMockUpdateExpectation struct {
  415. mock *UserRepositoryMock
  416. params *UserRepositoryMockUpdateParams
  417. results *UserRepositoryMockUpdateResults
  418. Counter uint64
  419. }
  420. // UserRepositoryMockUpdateParams contains parameters of the UserRepository.Update
  421. type UserRepositoryMockUpdateParams struct {
  422. ctx context.Context
  423. req models.UpdateUserRequest
  424. }
  425. // UserRepositoryMockUpdateResults contains results of the UserRepository.Update
  426. type UserRepositoryMockUpdateResults struct {
  427. err error
  428. }
  429. // Expect sets up expected params for UserRepository.Update
  430. func (mmUpdate *mUserRepositoryMockUpdate) Expect(ctx context.Context, req models.UpdateUserRequest) *mUserRepositoryMockUpdate {
  431. if mmUpdate.mock.funcUpdate != nil {
  432. mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Set")
  433. }
  434. if mmUpdate.defaultExpectation == nil {
  435. mmUpdate.defaultExpectation = &UserRepositoryMockUpdateExpectation{}
  436. }
  437. mmUpdate.defaultExpectation.params = &UserRepositoryMockUpdateParams{ctx, req}
  438. for _, e := range mmUpdate.expectations {
  439. if minimock.Equal(e.params, mmUpdate.defaultExpectation.params) {
  440. mmUpdate.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdate.defaultExpectation.params)
  441. }
  442. }
  443. return mmUpdate
  444. }
  445. // Inspect accepts an inspector function that has same arguments as the UserRepository.Update
  446. func (mmUpdate *mUserRepositoryMockUpdate) Inspect(f func(ctx context.Context, req models.UpdateUserRequest)) *mUserRepositoryMockUpdate {
  447. if mmUpdate.mock.inspectFuncUpdate != nil {
  448. mmUpdate.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Update")
  449. }
  450. mmUpdate.mock.inspectFuncUpdate = f
  451. return mmUpdate
  452. }
  453. // Return sets up results that will be returned by UserRepository.Update
  454. func (mmUpdate *mUserRepositoryMockUpdate) Return(err error) *UserRepositoryMock {
  455. if mmUpdate.mock.funcUpdate != nil {
  456. mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Set")
  457. }
  458. if mmUpdate.defaultExpectation == nil {
  459. mmUpdate.defaultExpectation = &UserRepositoryMockUpdateExpectation{mock: mmUpdate.mock}
  460. }
  461. mmUpdate.defaultExpectation.results = &UserRepositoryMockUpdateResults{err}
  462. return mmUpdate.mock
  463. }
  464. // Set uses given function f to mock the UserRepository.Update method
  465. func (mmUpdate *mUserRepositoryMockUpdate) Set(f func(ctx context.Context, req models.UpdateUserRequest) (err error)) *UserRepositoryMock {
  466. if mmUpdate.defaultExpectation != nil {
  467. mmUpdate.mock.t.Fatalf("Default expectation is already set for the UserRepository.Update method")
  468. }
  469. if len(mmUpdate.expectations) > 0 {
  470. mmUpdate.mock.t.Fatalf("Some expectations are already set for the UserRepository.Update method")
  471. }
  472. mmUpdate.mock.funcUpdate = f
  473. return mmUpdate.mock
  474. }
  475. // When sets expectation for the UserRepository.Update which will trigger the result defined by the following
  476. // Then helper
  477. func (mmUpdate *mUserRepositoryMockUpdate) When(ctx context.Context, req models.UpdateUserRequest) *UserRepositoryMockUpdateExpectation {
  478. if mmUpdate.mock.funcUpdate != nil {
  479. mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Set")
  480. }
  481. expectation := &UserRepositoryMockUpdateExpectation{
  482. mock: mmUpdate.mock,
  483. params: &UserRepositoryMockUpdateParams{ctx, req},
  484. }
  485. mmUpdate.expectations = append(mmUpdate.expectations, expectation)
  486. return expectation
  487. }
  488. // Then sets up UserRepository.Update return parameters for the expectation previously defined by the When method
  489. func (e *UserRepositoryMockUpdateExpectation) Then(err error) *UserRepositoryMock {
  490. e.results = &UserRepositoryMockUpdateResults{err}
  491. return e.mock
  492. }
  493. // Update implements interfaces.UserRepository
  494. func (mmUpdate *UserRepositoryMock) Update(ctx context.Context, req models.UpdateUserRequest) (err error) {
  495. mm_atomic.AddUint64(&mmUpdate.beforeUpdateCounter, 1)
  496. defer mm_atomic.AddUint64(&mmUpdate.afterUpdateCounter, 1)
  497. if mmUpdate.inspectFuncUpdate != nil {
  498. mmUpdate.inspectFuncUpdate(ctx, req)
  499. }
  500. mm_params := &UserRepositoryMockUpdateParams{ctx, req}
  501. // Record call args
  502. mmUpdate.UpdateMock.mutex.Lock()
  503. mmUpdate.UpdateMock.callArgs = append(mmUpdate.UpdateMock.callArgs, mm_params)
  504. mmUpdate.UpdateMock.mutex.Unlock()
  505. for _, e := range mmUpdate.UpdateMock.expectations {
  506. if minimock.Equal(e.params, mm_params) {
  507. mm_atomic.AddUint64(&e.Counter, 1)
  508. return e.results.err
  509. }
  510. }
  511. if mmUpdate.UpdateMock.defaultExpectation != nil {
  512. mm_atomic.AddUint64(&mmUpdate.UpdateMock.defaultExpectation.Counter, 1)
  513. mm_want := mmUpdate.UpdateMock.defaultExpectation.params
  514. mm_got := UserRepositoryMockUpdateParams{ctx, req}
  515. if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  516. mmUpdate.t.Errorf("UserRepositoryMock.Update got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  517. }
  518. mm_results := mmUpdate.UpdateMock.defaultExpectation.results
  519. if mm_results == nil {
  520. mmUpdate.t.Fatal("No results are set for the UserRepositoryMock.Update")
  521. }
  522. return (*mm_results).err
  523. }
  524. if mmUpdate.funcUpdate != nil {
  525. return mmUpdate.funcUpdate(ctx, req)
  526. }
  527. mmUpdate.t.Fatalf("Unexpected call to UserRepositoryMock.Update. %v %v", ctx, req)
  528. return
  529. }
  530. // UpdateAfterCounter returns a count of finished UserRepositoryMock.Update invocations
  531. func (mmUpdate *UserRepositoryMock) UpdateAfterCounter() uint64 {
  532. return mm_atomic.LoadUint64(&mmUpdate.afterUpdateCounter)
  533. }
  534. // UpdateBeforeCounter returns a count of UserRepositoryMock.Update invocations
  535. func (mmUpdate *UserRepositoryMock) UpdateBeforeCounter() uint64 {
  536. return mm_atomic.LoadUint64(&mmUpdate.beforeUpdateCounter)
  537. }
  538. // Calls returns a list of arguments used in each call to UserRepositoryMock.Update.
  539. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  540. func (mmUpdate *mUserRepositoryMockUpdate) Calls() []*UserRepositoryMockUpdateParams {
  541. mmUpdate.mutex.RLock()
  542. argCopy := make([]*UserRepositoryMockUpdateParams, len(mmUpdate.callArgs))
  543. copy(argCopy, mmUpdate.callArgs)
  544. mmUpdate.mutex.RUnlock()
  545. return argCopy
  546. }
  547. // MinimockUpdateDone returns true if the count of the Update invocations corresponds
  548. // the number of defined expectations
  549. func (m *UserRepositoryMock) MinimockUpdateDone() bool {
  550. for _, e := range m.UpdateMock.expectations {
  551. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  552. return false
  553. }
  554. }
  555. // if default expectation was set then invocations count should be greater than zero
  556. if m.UpdateMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterUpdateCounter) < 1 {
  557. return false
  558. }
  559. // if func was set then invocations count should be greater than zero
  560. if m.funcUpdate != nil && mm_atomic.LoadUint64(&m.afterUpdateCounter) < 1 {
  561. return false
  562. }
  563. return true
  564. }
  565. // MinimockUpdateInspect logs each unmet expectation
  566. func (m *UserRepositoryMock) MinimockUpdateInspect() {
  567. for _, e := range m.UpdateMock.expectations {
  568. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  569. m.t.Errorf("Expected call to UserRepositoryMock.Update with params: %#v", *e.params)
  570. }
  571. }
  572. // if default expectation was set then invocations count should be greater than zero
  573. if m.UpdateMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterUpdateCounter) < 1 {
  574. if m.UpdateMock.defaultExpectation.params == nil {
  575. m.t.Error("Expected call to UserRepositoryMock.Update")
  576. } else {
  577. m.t.Errorf("Expected call to UserRepositoryMock.Update with params: %#v", *m.UpdateMock.defaultExpectation.params)
  578. }
  579. }
  580. // if func was set then invocations count should be greater than zero
  581. if m.funcUpdate != nil && mm_atomic.LoadUint64(&m.afterUpdateCounter) < 1 {
  582. m.t.Error("Expected call to UserRepositoryMock.Update")
  583. }
  584. }
  585. // MinimockFinish checks that all mocked methods have been called the expected number of times
  586. func (m *UserRepositoryMock) MinimockFinish() {
  587. if !m.minimockDone() {
  588. m.MinimockAddInspect()
  589. m.MinimockGetInspect()
  590. m.MinimockUpdateInspect()
  591. m.t.FailNow()
  592. }
  593. }
  594. // MinimockWait waits for all mocked methods to be called the expected number of times
  595. func (m *UserRepositoryMock) MinimockWait(timeout mm_time.Duration) {
  596. timeoutCh := mm_time.After(timeout)
  597. for {
  598. if m.minimockDone() {
  599. return
  600. }
  601. select {
  602. case <-timeoutCh:
  603. m.MinimockFinish()
  604. return
  605. case <-mm_time.After(10 * mm_time.Millisecond):
  606. }
  607. }
  608. }
  609. func (m *UserRepositoryMock) minimockDone() bool {
  610. done := true
  611. return done &&
  612. m.MinimockAddDone() &&
  613. m.MinimockGetDone() &&
  614. m.MinimockUpdateDone()
  615. }