file_repository_minimock.go 17 KB

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