user_repository_minimock.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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/auth.UserRepository -o user_repository_minimock.go -n UserRepositoryMock -p mocks
  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 auth.UserRepository
  13. type UserRepositoryMock struct {
  14. t minimock.Tester
  15. finishOnce sync.Once
  16. funcGet func(ctx context.Context, username string) (up1 *models.User, err error)
  17. inspectFuncGet func(ctx context.Context, username string)
  18. afterGetCounter uint64
  19. beforeGetCounter uint64
  20. GetMock mUserRepositoryMockGet
  21. }
  22. // NewUserRepositoryMock returns a mock for auth.UserRepository
  23. func NewUserRepositoryMock(t minimock.Tester) *UserRepositoryMock {
  24. m := &UserRepositoryMock{t: t}
  25. if controller, ok := t.(minimock.MockController); ok {
  26. controller.RegisterMocker(m)
  27. }
  28. m.GetMock = mUserRepositoryMockGet{mock: m}
  29. m.GetMock.callArgs = []*UserRepositoryMockGetParams{}
  30. t.Cleanup(m.MinimockFinish)
  31. return m
  32. }
  33. type mUserRepositoryMockGet struct {
  34. optional bool
  35. mock *UserRepositoryMock
  36. defaultExpectation *UserRepositoryMockGetExpectation
  37. expectations []*UserRepositoryMockGetExpectation
  38. callArgs []*UserRepositoryMockGetParams
  39. mutex sync.RWMutex
  40. expectedInvocations uint64
  41. }
  42. // UserRepositoryMockGetExpectation specifies expectation struct of the UserRepository.Get
  43. type UserRepositoryMockGetExpectation struct {
  44. mock *UserRepositoryMock
  45. params *UserRepositoryMockGetParams
  46. paramPtrs *UserRepositoryMockGetParamPtrs
  47. results *UserRepositoryMockGetResults
  48. Counter uint64
  49. }
  50. // UserRepositoryMockGetParams contains parameters of the UserRepository.Get
  51. type UserRepositoryMockGetParams struct {
  52. ctx context.Context
  53. username string
  54. }
  55. // UserRepositoryMockGetParamPtrs contains pointers to parameters of the UserRepository.Get
  56. type UserRepositoryMockGetParamPtrs struct {
  57. ctx *context.Context
  58. username *string
  59. }
  60. // UserRepositoryMockGetResults contains results of the UserRepository.Get
  61. type UserRepositoryMockGetResults struct {
  62. up1 *models.User
  63. err error
  64. }
  65. // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
  66. // the test will fail minimock's automatic final call check if the mocked method was not called at least once.
  67. // Optional() makes method check to work in '0 or more' mode.
  68. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
  69. // catch the problems when the expected method call is totally skipped during test run.
  70. func (mmGet *mUserRepositoryMockGet) Optional() *mUserRepositoryMockGet {
  71. mmGet.optional = true
  72. return mmGet
  73. }
  74. // Expect sets up expected params for UserRepository.Get
  75. func (mmGet *mUserRepositoryMockGet) Expect(ctx context.Context, username string) *mUserRepositoryMockGet {
  76. if mmGet.mock.funcGet != nil {
  77. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  78. }
  79. if mmGet.defaultExpectation == nil {
  80. mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{}
  81. }
  82. if mmGet.defaultExpectation.paramPtrs != nil {
  83. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by ExpectParams functions")
  84. }
  85. mmGet.defaultExpectation.params = &UserRepositoryMockGetParams{ctx, username}
  86. for _, e := range mmGet.expectations {
  87. if minimock.Equal(e.params, mmGet.defaultExpectation.params) {
  88. mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params)
  89. }
  90. }
  91. return mmGet
  92. }
  93. // ExpectCtxParam1 sets up expected param ctx for UserRepository.Get
  94. func (mmGet *mUserRepositoryMockGet) ExpectCtxParam1(ctx context.Context) *mUserRepositoryMockGet {
  95. if mmGet.mock.funcGet != nil {
  96. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  97. }
  98. if mmGet.defaultExpectation == nil {
  99. mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{}
  100. }
  101. if mmGet.defaultExpectation.params != nil {
  102. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Expect")
  103. }
  104. if mmGet.defaultExpectation.paramPtrs == nil {
  105. mmGet.defaultExpectation.paramPtrs = &UserRepositoryMockGetParamPtrs{}
  106. }
  107. mmGet.defaultExpectation.paramPtrs.ctx = &ctx
  108. return mmGet
  109. }
  110. // ExpectUsernameParam2 sets up expected param username for UserRepository.Get
  111. func (mmGet *mUserRepositoryMockGet) ExpectUsernameParam2(username string) *mUserRepositoryMockGet {
  112. if mmGet.mock.funcGet != nil {
  113. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  114. }
  115. if mmGet.defaultExpectation == nil {
  116. mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{}
  117. }
  118. if mmGet.defaultExpectation.params != nil {
  119. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Expect")
  120. }
  121. if mmGet.defaultExpectation.paramPtrs == nil {
  122. mmGet.defaultExpectation.paramPtrs = &UserRepositoryMockGetParamPtrs{}
  123. }
  124. mmGet.defaultExpectation.paramPtrs.username = &username
  125. return mmGet
  126. }
  127. // Inspect accepts an inspector function that has same arguments as the UserRepository.Get
  128. func (mmGet *mUserRepositoryMockGet) Inspect(f func(ctx context.Context, username string)) *mUserRepositoryMockGet {
  129. if mmGet.mock.inspectFuncGet != nil {
  130. mmGet.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Get")
  131. }
  132. mmGet.mock.inspectFuncGet = f
  133. return mmGet
  134. }
  135. // Return sets up results that will be returned by UserRepository.Get
  136. func (mmGet *mUserRepositoryMockGet) Return(up1 *models.User, err error) *UserRepositoryMock {
  137. if mmGet.mock.funcGet != nil {
  138. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  139. }
  140. if mmGet.defaultExpectation == nil {
  141. mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{mock: mmGet.mock}
  142. }
  143. mmGet.defaultExpectation.results = &UserRepositoryMockGetResults{up1, err}
  144. return mmGet.mock
  145. }
  146. // Set uses given function f to mock the UserRepository.Get method
  147. func (mmGet *mUserRepositoryMockGet) Set(f func(ctx context.Context, username string) (up1 *models.User, err error)) *UserRepositoryMock {
  148. if mmGet.defaultExpectation != nil {
  149. mmGet.mock.t.Fatalf("Default expectation is already set for the UserRepository.Get method")
  150. }
  151. if len(mmGet.expectations) > 0 {
  152. mmGet.mock.t.Fatalf("Some expectations are already set for the UserRepository.Get method")
  153. }
  154. mmGet.mock.funcGet = f
  155. return mmGet.mock
  156. }
  157. // When sets expectation for the UserRepository.Get which will trigger the result defined by the following
  158. // Then helper
  159. func (mmGet *mUserRepositoryMockGet) When(ctx context.Context, username string) *UserRepositoryMockGetExpectation {
  160. if mmGet.mock.funcGet != nil {
  161. mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set")
  162. }
  163. expectation := &UserRepositoryMockGetExpectation{
  164. mock: mmGet.mock,
  165. params: &UserRepositoryMockGetParams{ctx, username},
  166. }
  167. mmGet.expectations = append(mmGet.expectations, expectation)
  168. return expectation
  169. }
  170. // Then sets up UserRepository.Get return parameters for the expectation previously defined by the When method
  171. func (e *UserRepositoryMockGetExpectation) Then(up1 *models.User, err error) *UserRepositoryMock {
  172. e.results = &UserRepositoryMockGetResults{up1, err}
  173. return e.mock
  174. }
  175. // Times sets number of times UserRepository.Get should be invoked
  176. func (mmGet *mUserRepositoryMockGet) Times(n uint64) *mUserRepositoryMockGet {
  177. if n == 0 {
  178. mmGet.mock.t.Fatalf("Times of UserRepositoryMock.Get mock can not be zero")
  179. }
  180. mm_atomic.StoreUint64(&mmGet.expectedInvocations, n)
  181. return mmGet
  182. }
  183. func (mmGet *mUserRepositoryMockGet) invocationsDone() bool {
  184. if len(mmGet.expectations) == 0 && mmGet.defaultExpectation == nil && mmGet.mock.funcGet == nil {
  185. return true
  186. }
  187. totalInvocations := mm_atomic.LoadUint64(&mmGet.mock.afterGetCounter)
  188. expectedInvocations := mm_atomic.LoadUint64(&mmGet.expectedInvocations)
  189. return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
  190. }
  191. // Get implements auth.UserRepository
  192. func (mmGet *UserRepositoryMock) Get(ctx context.Context, username string) (up1 *models.User, err error) {
  193. mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1)
  194. defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1)
  195. if mmGet.inspectFuncGet != nil {
  196. mmGet.inspectFuncGet(ctx, username)
  197. }
  198. mm_params := UserRepositoryMockGetParams{ctx, username}
  199. // Record call args
  200. mmGet.GetMock.mutex.Lock()
  201. mmGet.GetMock.callArgs = append(mmGet.GetMock.callArgs, &mm_params)
  202. mmGet.GetMock.mutex.Unlock()
  203. for _, e := range mmGet.GetMock.expectations {
  204. if minimock.Equal(*e.params, mm_params) {
  205. mm_atomic.AddUint64(&e.Counter, 1)
  206. return e.results.up1, e.results.err
  207. }
  208. }
  209. if mmGet.GetMock.defaultExpectation != nil {
  210. mm_atomic.AddUint64(&mmGet.GetMock.defaultExpectation.Counter, 1)
  211. mm_want := mmGet.GetMock.defaultExpectation.params
  212. mm_want_ptrs := mmGet.GetMock.defaultExpectation.paramPtrs
  213. mm_got := UserRepositoryMockGetParams{ctx, username}
  214. if mm_want_ptrs != nil {
  215. if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
  216. mmGet.t.Errorf("UserRepositoryMock.Get 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))
  217. }
  218. if mm_want_ptrs.username != nil && !minimock.Equal(*mm_want_ptrs.username, mm_got.username) {
  219. mmGet.t.Errorf("UserRepositoryMock.Get got unexpected parameter username, want: %#v, got: %#v%s\n", *mm_want_ptrs.username, mm_got.username, minimock.Diff(*mm_want_ptrs.username, mm_got.username))
  220. }
  221. } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
  222. mmGet.t.Errorf("UserRepositoryMock.Get got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
  223. }
  224. mm_results := mmGet.GetMock.defaultExpectation.results
  225. if mm_results == nil {
  226. mmGet.t.Fatal("No results are set for the UserRepositoryMock.Get")
  227. }
  228. return (*mm_results).up1, (*mm_results).err
  229. }
  230. if mmGet.funcGet != nil {
  231. return mmGet.funcGet(ctx, username)
  232. }
  233. mmGet.t.Fatalf("Unexpected call to UserRepositoryMock.Get. %v %v", ctx, username)
  234. return
  235. }
  236. // GetAfterCounter returns a count of finished UserRepositoryMock.Get invocations
  237. func (mmGet *UserRepositoryMock) GetAfterCounter() uint64 {
  238. return mm_atomic.LoadUint64(&mmGet.afterGetCounter)
  239. }
  240. // GetBeforeCounter returns a count of UserRepositoryMock.Get invocations
  241. func (mmGet *UserRepositoryMock) GetBeforeCounter() uint64 {
  242. return mm_atomic.LoadUint64(&mmGet.beforeGetCounter)
  243. }
  244. // Calls returns a list of arguments used in each call to UserRepositoryMock.Get.
  245. // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
  246. func (mmGet *mUserRepositoryMockGet) Calls() []*UserRepositoryMockGetParams {
  247. mmGet.mutex.RLock()
  248. argCopy := make([]*UserRepositoryMockGetParams, len(mmGet.callArgs))
  249. copy(argCopy, mmGet.callArgs)
  250. mmGet.mutex.RUnlock()
  251. return argCopy
  252. }
  253. // MinimockGetDone returns true if the count of the Get invocations corresponds
  254. // the number of defined expectations
  255. func (m *UserRepositoryMock) MinimockGetDone() bool {
  256. if m.GetMock.optional {
  257. // Optional methods provide '0 or more' call count restriction.
  258. return true
  259. }
  260. for _, e := range m.GetMock.expectations {
  261. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  262. return false
  263. }
  264. }
  265. return m.GetMock.invocationsDone()
  266. }
  267. // MinimockGetInspect logs each unmet expectation
  268. func (m *UserRepositoryMock) MinimockGetInspect() {
  269. for _, e := range m.GetMock.expectations {
  270. if mm_atomic.LoadUint64(&e.Counter) < 1 {
  271. m.t.Errorf("Expected call to UserRepositoryMock.Get with params: %#v", *e.params)
  272. }
  273. }
  274. afterGetCounter := mm_atomic.LoadUint64(&m.afterGetCounter)
  275. // if default expectation was set then invocations count should be greater than zero
  276. if m.GetMock.defaultExpectation != nil && afterGetCounter < 1 {
  277. if m.GetMock.defaultExpectation.params == nil {
  278. m.t.Error("Expected call to UserRepositoryMock.Get")
  279. } else {
  280. m.t.Errorf("Expected call to UserRepositoryMock.Get with params: %#v", *m.GetMock.defaultExpectation.params)
  281. }
  282. }
  283. // if func was set then invocations count should be greater than zero
  284. if m.funcGet != nil && afterGetCounter < 1 {
  285. m.t.Error("Expected call to UserRepositoryMock.Get")
  286. }
  287. if !m.GetMock.invocationsDone() && afterGetCounter > 0 {
  288. m.t.Errorf("Expected %d calls to UserRepositoryMock.Get but found %d calls",
  289. mm_atomic.LoadUint64(&m.GetMock.expectedInvocations), afterGetCounter)
  290. }
  291. }
  292. // MinimockFinish checks that all mocked methods have been called the expected number of times
  293. func (m *UserRepositoryMock) MinimockFinish() {
  294. m.finishOnce.Do(func() {
  295. if !m.minimockDone() {
  296. m.MinimockGetInspect()
  297. }
  298. })
  299. }
  300. // MinimockWait waits for all mocked methods to be called the expected number of times
  301. func (m *UserRepositoryMock) MinimockWait(timeout mm_time.Duration) {
  302. timeoutCh := mm_time.After(timeout)
  303. for {
  304. if m.minimockDone() {
  305. return
  306. }
  307. select {
  308. case <-timeoutCh:
  309. m.MinimockFinish()
  310. return
  311. case <-mm_time.After(10 * mm_time.Millisecond):
  312. }
  313. }
  314. }
  315. func (m *UserRepositoryMock) minimockDone() bool {
  316. done := true
  317. return done &&
  318. m.MinimockGetDone()
  319. }