file_repository_minimock.go 25 KB

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