package mocks // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. //go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/interfaces.FileRepository -o ./mocks/file_repository_minimock.go -n FileRepositoryMock import ( "mime/multipart" "sync" mm_atomic "sync/atomic" mm_time "time" "github.com/gofiber/fiber/v2" "github.com/gojuno/minimock/v3" ) // FileRepositoryMock implements interfaces.FileRepository type FileRepositoryMock struct { t minimock.Tester funcDelete func(path string) (err error) inspectFuncDelete func(path string) afterDeleteCounter uint64 beforeDeleteCounter uint64 DeleteMock mFileRepositoryMockDelete funcSave func(fctx *fiber.Ctx, header *multipart.FileHeader, path string) (err error) inspectFuncSave func(fctx *fiber.Ctx, header *multipart.FileHeader, path string) afterSaveCounter uint64 beforeSaveCounter uint64 SaveMock mFileRepositoryMockSave } // NewFileRepositoryMock returns a mock for interfaces.FileRepository func NewFileRepositoryMock(t minimock.Tester) *FileRepositoryMock { m := &FileRepositoryMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.DeleteMock = mFileRepositoryMockDelete{mock: m} m.DeleteMock.callArgs = []*FileRepositoryMockDeleteParams{} m.SaveMock = mFileRepositoryMockSave{mock: m} m.SaveMock.callArgs = []*FileRepositoryMockSaveParams{} return m } type mFileRepositoryMockDelete struct { mock *FileRepositoryMock defaultExpectation *FileRepositoryMockDeleteExpectation expectations []*FileRepositoryMockDeleteExpectation callArgs []*FileRepositoryMockDeleteParams mutex sync.RWMutex } // FileRepositoryMockDeleteExpectation specifies expectation struct of the FileRepository.Delete type FileRepositoryMockDeleteExpectation struct { mock *FileRepositoryMock params *FileRepositoryMockDeleteParams results *FileRepositoryMockDeleteResults Counter uint64 } // FileRepositoryMockDeleteParams contains parameters of the FileRepository.Delete type FileRepositoryMockDeleteParams struct { path string } // FileRepositoryMockDeleteResults contains results of the FileRepository.Delete type FileRepositoryMockDeleteResults struct { err error } // Expect sets up expected params for FileRepository.Delete func (mmDelete *mFileRepositoryMockDelete) Expect(path string) *mFileRepositoryMockDelete { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("FileRepositoryMock.Delete mock is already set by Set") } if mmDelete.defaultExpectation == nil { mmDelete.defaultExpectation = &FileRepositoryMockDeleteExpectation{} } mmDelete.defaultExpectation.params = &FileRepositoryMockDeleteParams{path} for _, e := range mmDelete.expectations { if minimock.Equal(e.params, mmDelete.defaultExpectation.params) { mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params) } } return mmDelete } // Inspect accepts an inspector function that has same arguments as the FileRepository.Delete func (mmDelete *mFileRepositoryMockDelete) Inspect(f func(path string)) *mFileRepositoryMockDelete { if mmDelete.mock.inspectFuncDelete != nil { mmDelete.mock.t.Fatalf("Inspect function is already set for FileRepositoryMock.Delete") } mmDelete.mock.inspectFuncDelete = f return mmDelete } // Return sets up results that will be returned by FileRepository.Delete func (mmDelete *mFileRepositoryMockDelete) Return(err error) *FileRepositoryMock { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("FileRepositoryMock.Delete mock is already set by Set") } if mmDelete.defaultExpectation == nil { mmDelete.defaultExpectation = &FileRepositoryMockDeleteExpectation{mock: mmDelete.mock} } mmDelete.defaultExpectation.results = &FileRepositoryMockDeleteResults{err} return mmDelete.mock } // Set uses given function f to mock the FileRepository.Delete method func (mmDelete *mFileRepositoryMockDelete) Set(f func(path string) (err error)) *FileRepositoryMock { if mmDelete.defaultExpectation != nil { mmDelete.mock.t.Fatalf("Default expectation is already set for the FileRepository.Delete method") } if len(mmDelete.expectations) > 0 { mmDelete.mock.t.Fatalf("Some expectations are already set for the FileRepository.Delete method") } mmDelete.mock.funcDelete = f return mmDelete.mock } // When sets expectation for the FileRepository.Delete which will trigger the result defined by the following // Then helper func (mmDelete *mFileRepositoryMockDelete) When(path string) *FileRepositoryMockDeleteExpectation { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("FileRepositoryMock.Delete mock is already set by Set") } expectation := &FileRepositoryMockDeleteExpectation{ mock: mmDelete.mock, params: &FileRepositoryMockDeleteParams{path}, } mmDelete.expectations = append(mmDelete.expectations, expectation) return expectation } // Then sets up FileRepository.Delete return parameters for the expectation previously defined by the When method func (e *FileRepositoryMockDeleteExpectation) Then(err error) *FileRepositoryMock { e.results = &FileRepositoryMockDeleteResults{err} return e.mock } // Delete implements interfaces.FileRepository func (mmDelete *FileRepositoryMock) Delete(path string) (err error) { mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1) defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1) if mmDelete.inspectFuncDelete != nil { mmDelete.inspectFuncDelete(path) } mm_params := &FileRepositoryMockDeleteParams{path} // Record call args mmDelete.DeleteMock.mutex.Lock() mmDelete.DeleteMock.callArgs = append(mmDelete.DeleteMock.callArgs, mm_params) mmDelete.DeleteMock.mutex.Unlock() for _, e := range mmDelete.DeleteMock.expectations { if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.err } } if mmDelete.DeleteMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmDelete.DeleteMock.defaultExpectation.Counter, 1) mm_want := mmDelete.DeleteMock.defaultExpectation.params mm_got := FileRepositoryMockDeleteParams{path} if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmDelete.t.Errorf("FileRepositoryMock.Delete got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmDelete.DeleteMock.defaultExpectation.results if mm_results == nil { mmDelete.t.Fatal("No results are set for the FileRepositoryMock.Delete") } return (*mm_results).err } if mmDelete.funcDelete != nil { return mmDelete.funcDelete(path) } mmDelete.t.Fatalf("Unexpected call to FileRepositoryMock.Delete. %v", path) return } // DeleteAfterCounter returns a count of finished FileRepositoryMock.Delete invocations func (mmDelete *FileRepositoryMock) DeleteAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmDelete.afterDeleteCounter) } // DeleteBeforeCounter returns a count of FileRepositoryMock.Delete invocations func (mmDelete *FileRepositoryMock) DeleteBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmDelete.beforeDeleteCounter) } // Calls returns a list of arguments used in each call to FileRepositoryMock.Delete. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmDelete *mFileRepositoryMockDelete) Calls() []*FileRepositoryMockDeleteParams { mmDelete.mutex.RLock() argCopy := make([]*FileRepositoryMockDeleteParams, len(mmDelete.callArgs)) copy(argCopy, mmDelete.callArgs) mmDelete.mutex.RUnlock() return argCopy } // MinimockDeleteDone returns true if the count of the Delete invocations corresponds // the number of defined expectations func (m *FileRepositoryMock) MinimockDeleteDone() bool { for _, e := range m.DeleteMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } // if default expectation was set then invocations count should be greater than zero if m.DeleteMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterDeleteCounter) < 1 { return false } // if func was set then invocations count should be greater than zero if m.funcDelete != nil && mm_atomic.LoadUint64(&m.afterDeleteCounter) < 1 { return false } return true } // MinimockDeleteInspect logs each unmet expectation func (m *FileRepositoryMock) MinimockDeleteInspect() { for _, e := range m.DeleteMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to FileRepositoryMock.Delete with params: %#v", *e.params) } } // if default expectation was set then invocations count should be greater than zero if m.DeleteMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterDeleteCounter) < 1 { if m.DeleteMock.defaultExpectation.params == nil { m.t.Error("Expected call to FileRepositoryMock.Delete") } else { m.t.Errorf("Expected call to FileRepositoryMock.Delete with params: %#v", *m.DeleteMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcDelete != nil && mm_atomic.LoadUint64(&m.afterDeleteCounter) < 1 { m.t.Error("Expected call to FileRepositoryMock.Delete") } } type mFileRepositoryMockSave struct { mock *FileRepositoryMock defaultExpectation *FileRepositoryMockSaveExpectation expectations []*FileRepositoryMockSaveExpectation callArgs []*FileRepositoryMockSaveParams mutex sync.RWMutex } // FileRepositoryMockSaveExpectation specifies expectation struct of the FileRepository.Save type FileRepositoryMockSaveExpectation struct { mock *FileRepositoryMock params *FileRepositoryMockSaveParams results *FileRepositoryMockSaveResults Counter uint64 } // FileRepositoryMockSaveParams contains parameters of the FileRepository.Save type FileRepositoryMockSaveParams struct { fctx *fiber.Ctx header *multipart.FileHeader path string } // FileRepositoryMockSaveResults contains results of the FileRepository.Save type FileRepositoryMockSaveResults struct { err error } // Expect sets up expected params for FileRepository.Save func (mmSave *mFileRepositoryMockSave) Expect(fctx *fiber.Ctx, header *multipart.FileHeader, path string) *mFileRepositoryMockSave { if mmSave.mock.funcSave != nil { mmSave.mock.t.Fatalf("FileRepositoryMock.Save mock is already set by Set") } if mmSave.defaultExpectation == nil { mmSave.defaultExpectation = &FileRepositoryMockSaveExpectation{} } mmSave.defaultExpectation.params = &FileRepositoryMockSaveParams{fctx, header, path} for _, e := range mmSave.expectations { if minimock.Equal(e.params, mmSave.defaultExpectation.params) { mmSave.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmSave.defaultExpectation.params) } } return mmSave } // Inspect accepts an inspector function that has same arguments as the FileRepository.Save func (mmSave *mFileRepositoryMockSave) Inspect(f func(fctx *fiber.Ctx, header *multipart.FileHeader, path string)) *mFileRepositoryMockSave { if mmSave.mock.inspectFuncSave != nil { mmSave.mock.t.Fatalf("Inspect function is already set for FileRepositoryMock.Save") } mmSave.mock.inspectFuncSave = f return mmSave } // Return sets up results that will be returned by FileRepository.Save func (mmSave *mFileRepositoryMockSave) Return(err error) *FileRepositoryMock { if mmSave.mock.funcSave != nil { mmSave.mock.t.Fatalf("FileRepositoryMock.Save mock is already set by Set") } if mmSave.defaultExpectation == nil { mmSave.defaultExpectation = &FileRepositoryMockSaveExpectation{mock: mmSave.mock} } mmSave.defaultExpectation.results = &FileRepositoryMockSaveResults{err} return mmSave.mock } // Set uses given function f to mock the FileRepository.Save method func (mmSave *mFileRepositoryMockSave) Set(f func(fctx *fiber.Ctx, header *multipart.FileHeader, path string) (err error)) *FileRepositoryMock { if mmSave.defaultExpectation != nil { mmSave.mock.t.Fatalf("Default expectation is already set for the FileRepository.Save method") } if len(mmSave.expectations) > 0 { mmSave.mock.t.Fatalf("Some expectations are already set for the FileRepository.Save method") } mmSave.mock.funcSave = f return mmSave.mock } // When sets expectation for the FileRepository.Save which will trigger the result defined by the following // Then helper func (mmSave *mFileRepositoryMockSave) When(fctx *fiber.Ctx, header *multipart.FileHeader, path string) *FileRepositoryMockSaveExpectation { if mmSave.mock.funcSave != nil { mmSave.mock.t.Fatalf("FileRepositoryMock.Save mock is already set by Set") } expectation := &FileRepositoryMockSaveExpectation{ mock: mmSave.mock, params: &FileRepositoryMockSaveParams{fctx, header, path}, } mmSave.expectations = append(mmSave.expectations, expectation) return expectation } // Then sets up FileRepository.Save return parameters for the expectation previously defined by the When method func (e *FileRepositoryMockSaveExpectation) Then(err error) *FileRepositoryMock { e.results = &FileRepositoryMockSaveResults{err} return e.mock } // Save implements interfaces.FileRepository func (mmSave *FileRepositoryMock) Save(fctx *fiber.Ctx, header *multipart.FileHeader, path string) (err error) { mm_atomic.AddUint64(&mmSave.beforeSaveCounter, 1) defer mm_atomic.AddUint64(&mmSave.afterSaveCounter, 1) if mmSave.inspectFuncSave != nil { mmSave.inspectFuncSave(fctx, header, path) } mm_params := &FileRepositoryMockSaveParams{fctx, header, path} // Record call args mmSave.SaveMock.mutex.Lock() mmSave.SaveMock.callArgs = append(mmSave.SaveMock.callArgs, mm_params) mmSave.SaveMock.mutex.Unlock() for _, e := range mmSave.SaveMock.expectations { if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.err } } if mmSave.SaveMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmSave.SaveMock.defaultExpectation.Counter, 1) mm_want := mmSave.SaveMock.defaultExpectation.params mm_got := FileRepositoryMockSaveParams{fctx, header, path} if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmSave.t.Errorf("FileRepositoryMock.Save got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmSave.SaveMock.defaultExpectation.results if mm_results == nil { mmSave.t.Fatal("No results are set for the FileRepositoryMock.Save") } return (*mm_results).err } if mmSave.funcSave != nil { return mmSave.funcSave(fctx, header, path) } mmSave.t.Fatalf("Unexpected call to FileRepositoryMock.Save. %v %v %v", fctx, header, path) return } // SaveAfterCounter returns a count of finished FileRepositoryMock.Save invocations func (mmSave *FileRepositoryMock) SaveAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmSave.afterSaveCounter) } // SaveBeforeCounter returns a count of FileRepositoryMock.Save invocations func (mmSave *FileRepositoryMock) SaveBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmSave.beforeSaveCounter) } // Calls returns a list of arguments used in each call to FileRepositoryMock.Save. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmSave *mFileRepositoryMockSave) Calls() []*FileRepositoryMockSaveParams { mmSave.mutex.RLock() argCopy := make([]*FileRepositoryMockSaveParams, len(mmSave.callArgs)) copy(argCopy, mmSave.callArgs) mmSave.mutex.RUnlock() return argCopy } // MinimockSaveDone returns true if the count of the Save invocations corresponds // the number of defined expectations func (m *FileRepositoryMock) MinimockSaveDone() bool { for _, e := range m.SaveMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } // if default expectation was set then invocations count should be greater than zero if m.SaveMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterSaveCounter) < 1 { return false } // if func was set then invocations count should be greater than zero if m.funcSave != nil && mm_atomic.LoadUint64(&m.afterSaveCounter) < 1 { return false } return true } // MinimockSaveInspect logs each unmet expectation func (m *FileRepositoryMock) MinimockSaveInspect() { for _, e := range m.SaveMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to FileRepositoryMock.Save with params: %#v", *e.params) } } // if default expectation was set then invocations count should be greater than zero if m.SaveMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterSaveCounter) < 1 { if m.SaveMock.defaultExpectation.params == nil { m.t.Error("Expected call to FileRepositoryMock.Save") } else { m.t.Errorf("Expected call to FileRepositoryMock.Save with params: %#v", *m.SaveMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcSave != nil && mm_atomic.LoadUint64(&m.afterSaveCounter) < 1 { m.t.Error("Expected call to FileRepositoryMock.Save") } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *FileRepositoryMock) MinimockFinish() { if !m.minimockDone() { m.MinimockDeleteInspect() m.MinimockSaveInspect() m.t.FailNow() } } // MinimockWait waits for all mocked methods to be called the expected number of times func (m *FileRepositoryMock) MinimockWait(timeout mm_time.Duration) { timeoutCh := mm_time.After(timeout) for { if m.minimockDone() { return } select { case <-timeoutCh: m.MinimockFinish() return case <-mm_time.After(10 * mm_time.Millisecond): } } } func (m *FileRepositoryMock) minimockDone() bool { done := true return done && m.MinimockDeleteDone() && m.MinimockSaveDone() }