user_repository_minimock.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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/dmitriygnatenko-v2/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/dmitriygnatenko-v2/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. }
  26. // NewUserRepositoryMock returns a mock for interfaces.UserRepository
  27. func NewUserRepositoryMock(t minimock.Tester) *UserRepositoryMock {
  28. m := &UserRepositoryMock{t: t}
  29. if controller, ok := t.(minimock.MockController); ok {
  30. controller.RegisterMocker(m)
  31. }
  32. m.AddMock = mUserRepositoryMockAdd{mock: m}
  33. m.AddMock.callArgs = []*UserRepositoryMockAddParams{}
  34. m.GetMock = mUserRepositoryMockGet{mock: m}
  35. m.GetMock.callArgs = []*UserRepositoryMockGetParams{}
  36. return m
  37. }
  38. type mUserRepositoryMockAdd struct {
  39. mock *UserRepositoryMock
  40. defaultExpectation *UserRepositoryMockAddExpectation
  41. expectations []*UserRepositoryMockAddExpectation
  42. callArgs []*UserRepositoryMockAddParams
  43. mutex sync.RWMutex
  44. }
  45. // UserRepositoryMockAddExpectation specifies expectation struct of the UserRepository.Add
  46. type UserRepositoryMockAddExpectation struct {
  47. mock *UserRepositoryMock
  48. params *UserRepositoryMockAddParams
  49. results *UserRepositoryMockAddResults
  50. Counter uint64
  51. }
  52. // UserRepositoryMockAddParams contains parameters of the UserRepository.Add
  53. type UserRepositoryMockAddParams struct {
  54. ctx context.Context
  55. username string
  56. password string
  57. }
  58. // UserRepositoryMockAddResults contains results of the UserRepository.Add
  59. type UserRepositoryMockAddResults struct {
  60. i1 int
  61. err error
  62. }
  63. // Expect sets up expected params for UserRepository.Add
  64. func (mmAdd *mUserRepositoryMockAdd) Expect(ctx context.Context, username string, password string) *mUserRepositoryMockAdd {
  65. if mmAdd.mock.funcAdd != nil {
  66. mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set")
  67. }
  68. if mmAdd.defaultExpectation == nil {
  69. mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{}
  70. }
  71. mmAdd.defaultExpectation.params = &UserRepositoryMockAddParams{ctx, username, password}
  72. for _, e := range mmAdd.expectations {
  73. if minimock.Equal(e.params, mmAdd.defaultExpectation.params) {
  74. mmAdd.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmAdd.defaultExpectation.params)
  75. }
  76. }
  77. return mmAdd
  78. }
  79. // Inspect accepts an inspector function that has same arguments as the UserRepository.Add
  80. func (mmAdd *mUserRepositoryMockAdd) Inspect(f func(ctx context.Context, username string, password string)) *mUserRepositoryMockAdd {
  81. if mmAdd.mock.inspectFuncAdd != nil {
  82. mmAdd.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Add")
  83. }
  84. mmAdd.mock.inspectFuncAdd = f
  85. return mmAdd
  86. }
  87. // Return sets up results that will be returned by UserRepository.Add
  88. func (mmAdd *mUserRepositoryMockAdd) Return(i1 int, err error) *UserRepositoryMock {
  89. if mmAdd.mock.funcAdd != nil {
  90. mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set")
  91. }
  92. if mmAdd.defaultExpectation == nil {
  93. mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{mock: mmAdd.mock}
  94. }
  95. mmAdd.defaultExpectation.results = &UserRepositoryMockAddResults{i1, err}
  96. return mmAdd.mock
  97. }
  98. // Set uses given function f to mock the UserRepository.Add method
  99. func (mmAdd *mUserRepositoryMockAdd) Set(f func(ctx context.Context, username string, password string) (i1 int, err error)) *UserRepositoryMock {
  100. if mmAdd.defaultExpectation != nil {
  101. mmAdd.mock.t.Fatalf("Default expectation is already set for the UserRepository.Add method")
  102. }
  103. if len(mmAdd.expectations) > 0 {
  104. mmAdd.mock.t.Fatalf("Some expectations are already set for the UserRepository.Add method")
  105. }
  106. mmAdd.mock.funcAdd = f
  107. return mmAdd.mock
  108. }
  109. // When sets expectation for the UserRepository.Add which will trigger the result defined by the following
  110. // Then helper
  111. func (mmAdd *mUserRepositoryMockAdd) When(ctx context.Context, username string, password string) *UserRepositoryMockAddExpectation {
  112. if mmAdd.mock.funcAdd != nil {
  113. mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set")
  114. }
  115. expectation := &UserRepositoryMockAddExpectation{
  116. mock: mmAdd.mock,
  117. params: &UserRepositoryMockAddParams{ctx, username, password},
  118. }
  119. mmAdd.expectations = append(mmAdd.expectations, expectation)
  120. return expectation
  121. }
  122. // Then sets up UserRepository.Add return parameters for the expectation previously defined by the When method
  123. func (e *UserRepositoryMockAddExpectation) Then(i1 int, err error) *UserRepositoryMock {
  124. e.results = &UserRepositoryMockAddResults{i1, err}
  125. return e.mock
  126. }
  127. // Add implements interfaces.UserRepository
  128. func (mmAdd *UserRepositoryMock) Add(ctx context.Context, username string, password string) (i1 int, err error) {
  129. mm_atomic.AddUint64(&mmAdd.beforeAddCounter, 1)
  130. defer mm_atomic.AddUint64(&mmAdd.afterAddCounter, 1)
  131. if mmAdd.inspectFuncAdd != nil {
  132. mmAdd.inspectFuncAdd(ctx, username, password)
  133. }
  134. mm_params := &UserRepositoryMockAddParams{ctx, username, password}
  135. // Record call args
  136. mmAdd.AddMock.mutex.Lock()
  137. mmAdd.AddMock.callArgs = append(mmAdd.AddMock.callArgs, mm_params)
  138. mmAdd.AddMock.mutex.Unlock()
  139. for _, e := range mmAdd.AddMock.expectations {
  140. if minimock.Equal(e.params, mm_params) {
  141. mm_atomic.AddUint64(&e.Counter, 1)
  142. return e.results.i1, e.results.err
  143. }
  144. }
  145. if mmAdd.AddMock.defaultExpectation != nil {
  146. mm_atomic.AddUint64(&mmAdd.AddMock.defaultExpectation.Counter, 1)
  147. mm_want := mmAdd.AddMock.defaultExpectation.params
  148. mm_got := UserRepositoryMockAddParams{ctx, username, password}
  149. if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  150. mmAdd.t.Errorf("UserRepositoryMock.Add got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  151. }
  152. mm_results := mmAdd.AddMock.defaultExpectation.results
  153. if mm_results == nil {
  154. mmAdd.t.Fatal("No results are set for the UserRepositoryMock.Add")
  155. }
  156. return (*mm_results).i1, (*mm_results).err
  157. }
  158. if mmAdd.funcAdd != nil {
  159. return mmAdd.funcAdd(ctx, username, password)
  160. }
  161. mmAdd.t.Fatalf("Unexpected call to UserRepositoryMock.Add. %v %v %v", ctx, username, password)
  162. return
  163. }
  164. // AddAfterCounter returns a count of finished UserRepositoryMock.Add invocations
  165. func (mmAdd *UserRepositoryMock) AddAfterCounter() uint64 {
  166. return mm_atomic.LoadUint64(&mmAdd.afterAddCounter)
  167. }
  168. // AddBeforeCounter returns a count of UserRepositoryMock.Add invocations
  169. func (mmAdd *UserRepositoryMock) AddBeforeCounter() uint64 {
  170. return mm_atomic.LoadUint64(&mmAdd.beforeAddCounter)
  171. }
  172. // Calls returns a list of arguments used in each call to UserRepositoryMock.Add.
  173. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  174. func (mmAdd *mUserRepositoryMockAdd) Calls() []*UserRepositoryMockAddParams {
  175. mmAdd.mutex.RLock()
  176. argCopy := make([]*UserRepositoryMockAddParams, len(mmAdd.callArgs))
  177. copy(argCopy, mmAdd.callArgs)
  178. mmAdd.mutex.RUnlock()
  179. return argCopy
  180. }
  181. // MinimockAddDone returns true if the count of the Add invocations corresponds
  182. // the number of defined expectations
  183. func (m *UserRepositoryMock) MinimockAddDone() bool {
  184. for _, e := range m.AddMock.expectations {
  185. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  186. return false
  187. }
  188. }
  189. // if default expectation was set then invocations count should be greater than zero
  190. if m.AddMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterAddCounter) < 1 {
  191. return false
  192. }
  193. // if func was set then invocations count should be greater than zero
  194. if m.funcAdd != nil && mm_atomic.LoadUint64(&m.afterAddCounter) < 1 {
  195. return false
  196. }
  197. return true
  198. }
  199. // MinimockAddInspect logs each unmet expectation
  200. func (m *UserRepositoryMock) MinimockAddInspect() {
  201. for _, e := range m.AddMock.expectations {
  202. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  203. m.t.Errorf("Expected call to UserRepositoryMock.Add with params: %#v", *e.params)
  204. }
  205. }
  206. // if default expectation was set then invocations count should be greater than zero
  207. if m.AddMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterAddCounter) < 1 {
  208. if m.AddMock.defaultExpectation.params == nil {
  209. m.t.Error("Expected call to UserRepositoryMock.Add")
  210. } else {
  211. m.t.Errorf("Expected call to UserRepositoryMock.Add with params: %#v", *m.AddMock.defaultExpectation.params)
  212. }
  213. }
  214. // if func was set then invocations count should be greater than zero
  215. if m.funcAdd != nil && mm_atomic.LoadUint64(&m.afterAddCounter) < 1 {
  216. m.t.Error("Expected call to UserRepositoryMock.Add")
  217. }
  218. }
  219. type mUserRepositoryMockGet struct {
  220. mock *UserRepositoryMock
  221. defaultExpectation *UserRepositoryMockGetExpectation
  222. expectations []*UserRepositoryMockGetExpectation
  223. callArgs []*UserRepositoryMockGetParams
  224. mutex sync.RWMutex
  225. }
  226. // UserRepositoryMockGetExpectation specifies expectation struct of the UserRepository.Get
  227. type UserRepositoryMockGetExpectation struct {
  228. mock *UserRepositoryMock
  229. params *UserRepositoryMockGetParams
  230. results *UserRepositoryMockGetResults
  231. Counter uint64
  232. }
  233. // UserRepositoryMockGetParams contains parameters of the UserRepository.Get
  234. type UserRepositoryMockGetParams struct {
  235. ctx context.Context
  236. username string
  237. }
  238. // UserRepositoryMockGetResults contains results of the UserRepository.Get
  239. type UserRepositoryMockGetResults struct {
  240. up1 *models.User
  241. err error
  242. }
  243. // Expect sets up expected params for UserRepository.Get
  244. func (mmGet *mUserRepositoryMockGet) Expect(ctx context.Context, username string) *mUserRepositoryMockGet {
  245. if mmGet.mock.funcGet != nil {
  246. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  247. }
  248. if mmGet.defaultExpectation == nil {
  249. mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{}
  250. }
  251. mmGet.defaultExpectation.params = &UserRepositoryMockGetParams{ctx, username}
  252. for _, e := range mmGet.expectations {
  253. if minimock.Equal(e.params, mmGet.defaultExpectation.params) {
  254. mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params)
  255. }
  256. }
  257. return mmGet
  258. }
  259. // Inspect accepts an inspector function that has same arguments as the UserRepository.Get
  260. func (mmGet *mUserRepositoryMockGet) Inspect(f func(ctx context.Context, username string)) *mUserRepositoryMockGet {
  261. if mmGet.mock.inspectFuncGet != nil {
  262. mmGet.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Get")
  263. }
  264. mmGet.mock.inspectFuncGet = f
  265. return mmGet
  266. }
  267. // Return sets up results that will be returned by UserRepository.Get
  268. func (mmGet *mUserRepositoryMockGet) Return(up1 *models.User, err error) *UserRepositoryMock {
  269. if mmGet.mock.funcGet != nil {
  270. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  271. }
  272. if mmGet.defaultExpectation == nil {
  273. mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{mock: mmGet.mock}
  274. }
  275. mmGet.defaultExpectation.results = &UserRepositoryMockGetResults{up1, err}
  276. return mmGet.mock
  277. }
  278. // Set uses given function f to mock the UserRepository.Get method
  279. func (mmGet *mUserRepositoryMockGet) Set(f func(ctx context.Context, username string) (up1 *models.User, err error)) *UserRepositoryMock {
  280. if mmGet.defaultExpectation != nil {
  281. mmGet.mock.t.Fatalf("Default expectation is already set for the UserRepository.Get method")
  282. }
  283. if len(mmGet.expectations) > 0 {
  284. mmGet.mock.t.Fatalf("Some expectations are already set for the UserRepository.Get method")
  285. }
  286. mmGet.mock.funcGet = f
  287. return mmGet.mock
  288. }
  289. // When sets expectation for the UserRepository.Get which will trigger the result defined by the following
  290. // Then helper
  291. func (mmGet *mUserRepositoryMockGet) When(ctx context.Context, username string) *UserRepositoryMockGetExpectation {
  292. if mmGet.mock.funcGet != nil {
  293. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  294. }
  295. expectation := &UserRepositoryMockGetExpectation{
  296. mock: mmGet.mock,
  297. params: &UserRepositoryMockGetParams{ctx, username},
  298. }
  299. mmGet.expectations = append(mmGet.expectations, expectation)
  300. return expectation
  301. }
  302. // Then sets up UserRepository.Get return parameters for the expectation previously defined by the When method
  303. func (e *UserRepositoryMockGetExpectation) Then(up1 *models.User, err error) *UserRepositoryMock {
  304. e.results = &UserRepositoryMockGetResults{up1, err}
  305. return e.mock
  306. }
  307. // Get implements interfaces.UserRepository
  308. func (mmGet *UserRepositoryMock) Get(ctx context.Context, username string) (up1 *models.User, err error) {
  309. mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1)
  310. defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1)
  311. if mmGet.inspectFuncGet != nil {
  312. mmGet.inspectFuncGet(ctx, username)
  313. }
  314. mm_params := &UserRepositoryMockGetParams{ctx, username}
  315. // Record call args
  316. mmGet.GetMock.mutex.Lock()
  317. mmGet.GetMock.callArgs = append(mmGet.GetMock.callArgs, mm_params)
  318. mmGet.GetMock.mutex.Unlock()
  319. for _, e := range mmGet.GetMock.expectations {
  320. if minimock.Equal(e.params, mm_params) {
  321. mm_atomic.AddUint64(&e.Counter, 1)
  322. return e.results.up1, e.results.err
  323. }
  324. }
  325. if mmGet.GetMock.defaultExpectation != nil {
  326. mm_atomic.AddUint64(&mmGet.GetMock.defaultExpectation.Counter, 1)
  327. mm_want := mmGet.GetMock.defaultExpectation.params
  328. mm_got := UserRepositoryMockGetParams{ctx, username}
  329. if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  330. mmGet.t.Errorf("UserRepositoryMock.Get got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  331. }
  332. mm_results := mmGet.GetMock.defaultExpectation.results
  333. if mm_results == nil {
  334. mmGet.t.Fatal("No results are set for the UserRepositoryMock.Get")
  335. }
  336. return (*mm_results).up1, (*mm_results).err
  337. }
  338. if mmGet.funcGet != nil {
  339. return mmGet.funcGet(ctx, username)
  340. }
  341. mmGet.t.Fatalf("Unexpected call to UserRepositoryMock.Get. %v %v", ctx, username)
  342. return
  343. }
  344. // GetAfterCounter returns a count of finished UserRepositoryMock.Get invocations
  345. func (mmGet *UserRepositoryMock) GetAfterCounter() uint64 {
  346. return mm_atomic.LoadUint64(&mmGet.afterGetCounter)
  347. }
  348. // GetBeforeCounter returns a count of UserRepositoryMock.Get invocations
  349. func (mmGet *UserRepositoryMock) GetBeforeCounter() uint64 {
  350. return mm_atomic.LoadUint64(&mmGet.beforeGetCounter)
  351. }
  352. // Calls returns a list of arguments used in each call to UserRepositoryMock.Get.
  353. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  354. func (mmGet *mUserRepositoryMockGet) Calls() []*UserRepositoryMockGetParams {
  355. mmGet.mutex.RLock()
  356. argCopy := make([]*UserRepositoryMockGetParams, len(mmGet.callArgs))
  357. copy(argCopy, mmGet.callArgs)
  358. mmGet.mutex.RUnlock()
  359. return argCopy
  360. }
  361. // MinimockGetDone returns true if the count of the Get invocations corresponds
  362. // the number of defined expectations
  363. func (m *UserRepositoryMock) MinimockGetDone() bool {
  364. for _, e := range m.GetMock.expectations {
  365. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  366. return false
  367. }
  368. }
  369. // if default expectation was set then invocations count should be greater than zero
  370. if m.GetMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 {
  371. return false
  372. }
  373. // if func was set then invocations count should be greater than zero
  374. if m.funcGet != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 {
  375. return false
  376. }
  377. return true
  378. }
  379. // MinimockGetInspect logs each unmet expectation
  380. func (m *UserRepositoryMock) MinimockGetInspect() {
  381. for _, e := range m.GetMock.expectations {
  382. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  383. m.t.Errorf("Expected call to UserRepositoryMock.Get with params: %#v", *e.params)
  384. }
  385. }
  386. // if default expectation was set then invocations count should be greater than zero
  387. if m.GetMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 {
  388. if m.GetMock.defaultExpectation.params == nil {
  389. m.t.Error("Expected call to UserRepositoryMock.Get")
  390. } else {
  391. m.t.Errorf("Expected call to UserRepositoryMock.Get with params: %#v", *m.GetMock.defaultExpectation.params)
  392. }
  393. }
  394. // if func was set then invocations count should be greater than zero
  395. if m.funcGet != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 {
  396. m.t.Error("Expected call to UserRepositoryMock.Get")
  397. }
  398. }
  399. // MinimockFinish checks that all mocked methods have been called the expected number of times
  400. func (m *UserRepositoryMock) MinimockFinish() {
  401. if !m.minimockDone() {
  402. m.MinimockAddInspect()
  403. m.MinimockGetInspect()
  404. m.t.FailNow()
  405. }
  406. }
  407. // MinimockWait waits for all mocked methods to be called the expected number of times
  408. func (m *UserRepositoryMock) MinimockWait(timeout mm_time.Duration) {
  409. timeoutCh := mm_time.After(timeout)
  410. for {
  411. if m.minimockDone() {
  412. return
  413. }
  414. select {
  415. case <-timeoutCh:
  416. m.MinimockFinish()
  417. return
  418. case <-mm_time.After(10 * mm_time.Millisecond):
  419. }
  420. }
  421. }
  422. func (m *UserRepositoryMock) minimockDone() bool {
  423. done := true
  424. return done &&
  425. m.MinimockAddDone() &&
  426. m.MinimockGetDone()
  427. }