file_repository_minimock.go 12 KB

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