// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT. package mocks //go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place.ThingImageRepository -o thing_image_repository_minimock.go -n ThingImageRepositoryMock -p mocks import ( "context" "database/sql" "sync" mm_atomic "sync/atomic" mm_time "time" "git.dmitriygnatenko.ru/dima/homethings/internal/models" "github.com/gojuno/minimock/v3" ) // ThingImageRepositoryMock implements place.ThingImageRepository type ThingImageRepositoryMock struct { t minimock.Tester finishOnce sync.Once funcDelete func(ctx context.Context, imageID int, tx *sql.Tx) (err error) inspectFuncDelete func(ctx context.Context, imageID int, tx *sql.Tx) afterDeleteCounter uint64 beforeDeleteCounter uint64 DeleteMock mThingImageRepositoryMockDelete funcGetByThingID func(ctx context.Context, thingID int) (ia1 []models.Image, err error) inspectFuncGetByThingID func(ctx context.Context, thingID int) afterGetByThingIDCounter uint64 beforeGetByThingIDCounter uint64 GetByThingIDMock mThingImageRepositoryMockGetByThingID } // NewThingImageRepositoryMock returns a mock for place.ThingImageRepository func NewThingImageRepositoryMock(t minimock.Tester) *ThingImageRepositoryMock { m := &ThingImageRepositoryMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.DeleteMock = mThingImageRepositoryMockDelete{mock: m} m.DeleteMock.callArgs = []*ThingImageRepositoryMockDeleteParams{} m.GetByThingIDMock = mThingImageRepositoryMockGetByThingID{mock: m} m.GetByThingIDMock.callArgs = []*ThingImageRepositoryMockGetByThingIDParams{} t.Cleanup(m.MinimockFinish) return m } type mThingImageRepositoryMockDelete struct { optional bool mock *ThingImageRepositoryMock defaultExpectation *ThingImageRepositoryMockDeleteExpectation expectations []*ThingImageRepositoryMockDeleteExpectation callArgs []*ThingImageRepositoryMockDeleteParams mutex sync.RWMutex expectedInvocations uint64 } // ThingImageRepositoryMockDeleteExpectation specifies expectation struct of the ThingImageRepository.Delete type ThingImageRepositoryMockDeleteExpectation struct { mock *ThingImageRepositoryMock params *ThingImageRepositoryMockDeleteParams paramPtrs *ThingImageRepositoryMockDeleteParamPtrs results *ThingImageRepositoryMockDeleteResults Counter uint64 } // ThingImageRepositoryMockDeleteParams contains parameters of the ThingImageRepository.Delete type ThingImageRepositoryMockDeleteParams struct { ctx context.Context imageID int tx *sql.Tx } // ThingImageRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingImageRepository.Delete type ThingImageRepositoryMockDeleteParamPtrs struct { ctx *context.Context imageID *int tx **sql.Tx } // ThingImageRepositoryMockDeleteResults contains results of the ThingImageRepository.Delete type ThingImageRepositoryMockDeleteResults struct { err error } // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning // the test will fail minimock's automatic final call check if the mocked method was not called at least once. // Optional() makes method check to work in '0 or more' mode. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to // catch the problems when the expected method call is totally skipped during test run. func (mmDelete *mThingImageRepositoryMockDelete) Optional() *mThingImageRepositoryMockDelete { mmDelete.optional = true return mmDelete } // Expect sets up expected params for ThingImageRepository.Delete func (mmDelete *mThingImageRepositoryMockDelete) Expect(ctx context.Context, imageID int, tx *sql.Tx) *mThingImageRepositoryMockDelete { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set") } if mmDelete.defaultExpectation == nil { mmDelete.defaultExpectation = &ThingImageRepositoryMockDeleteExpectation{} } if mmDelete.defaultExpectation.paramPtrs != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by ExpectParams functions") } mmDelete.defaultExpectation.params = &ThingImageRepositoryMockDeleteParams{ctx, imageID, tx} 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 } // ExpectCtxParam1 sets up expected param ctx for ThingImageRepository.Delete func (mmDelete *mThingImageRepositoryMockDelete) ExpectCtxParam1(ctx context.Context) *mThingImageRepositoryMockDelete { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set") } if mmDelete.defaultExpectation == nil { mmDelete.defaultExpectation = &ThingImageRepositoryMockDeleteExpectation{} } if mmDelete.defaultExpectation.params != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Expect") } if mmDelete.defaultExpectation.paramPtrs == nil { mmDelete.defaultExpectation.paramPtrs = &ThingImageRepositoryMockDeleteParamPtrs{} } mmDelete.defaultExpectation.paramPtrs.ctx = &ctx return mmDelete } // ExpectImageIDParam2 sets up expected param imageID for ThingImageRepository.Delete func (mmDelete *mThingImageRepositoryMockDelete) ExpectImageIDParam2(imageID int) *mThingImageRepositoryMockDelete { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set") } if mmDelete.defaultExpectation == nil { mmDelete.defaultExpectation = &ThingImageRepositoryMockDeleteExpectation{} } if mmDelete.defaultExpectation.params != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Expect") } if mmDelete.defaultExpectation.paramPtrs == nil { mmDelete.defaultExpectation.paramPtrs = &ThingImageRepositoryMockDeleteParamPtrs{} } mmDelete.defaultExpectation.paramPtrs.imageID = &imageID return mmDelete } // ExpectTxParam3 sets up expected param tx for ThingImageRepository.Delete func (mmDelete *mThingImageRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mThingImageRepositoryMockDelete { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set") } if mmDelete.defaultExpectation == nil { mmDelete.defaultExpectation = &ThingImageRepositoryMockDeleteExpectation{} } if mmDelete.defaultExpectation.params != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Expect") } if mmDelete.defaultExpectation.paramPtrs == nil { mmDelete.defaultExpectation.paramPtrs = &ThingImageRepositoryMockDeleteParamPtrs{} } mmDelete.defaultExpectation.paramPtrs.tx = &tx return mmDelete } // Inspect accepts an inspector function that has same arguments as the ThingImageRepository.Delete func (mmDelete *mThingImageRepositoryMockDelete) Inspect(f func(ctx context.Context, imageID int, tx *sql.Tx)) *mThingImageRepositoryMockDelete { if mmDelete.mock.inspectFuncDelete != nil { mmDelete.mock.t.Fatalf("Inspect function is already set for ThingImageRepositoryMock.Delete") } mmDelete.mock.inspectFuncDelete = f return mmDelete } // Return sets up results that will be returned by ThingImageRepository.Delete func (mmDelete *mThingImageRepositoryMockDelete) Return(err error) *ThingImageRepositoryMock { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set") } if mmDelete.defaultExpectation == nil { mmDelete.defaultExpectation = &ThingImageRepositoryMockDeleteExpectation{mock: mmDelete.mock} } mmDelete.defaultExpectation.results = &ThingImageRepositoryMockDeleteResults{err} return mmDelete.mock } // Set uses given function f to mock the ThingImageRepository.Delete method func (mmDelete *mThingImageRepositoryMockDelete) Set(f func(ctx context.Context, imageID int, tx *sql.Tx) (err error)) *ThingImageRepositoryMock { if mmDelete.defaultExpectation != nil { mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingImageRepository.Delete method") } if len(mmDelete.expectations) > 0 { mmDelete.mock.t.Fatalf("Some expectations are already set for the ThingImageRepository.Delete method") } mmDelete.mock.funcDelete = f return mmDelete.mock } // When sets expectation for the ThingImageRepository.Delete which will trigger the result defined by the following // Then helper func (mmDelete *mThingImageRepositoryMockDelete) When(ctx context.Context, imageID int, tx *sql.Tx) *ThingImageRepositoryMockDeleteExpectation { if mmDelete.mock.funcDelete != nil { mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set") } expectation := &ThingImageRepositoryMockDeleteExpectation{ mock: mmDelete.mock, params: &ThingImageRepositoryMockDeleteParams{ctx, imageID, tx}, } mmDelete.expectations = append(mmDelete.expectations, expectation) return expectation } // Then sets up ThingImageRepository.Delete return parameters for the expectation previously defined by the When method func (e *ThingImageRepositoryMockDeleteExpectation) Then(err error) *ThingImageRepositoryMock { e.results = &ThingImageRepositoryMockDeleteResults{err} return e.mock } // Times sets number of times ThingImageRepository.Delete should be invoked func (mmDelete *mThingImageRepositoryMockDelete) Times(n uint64) *mThingImageRepositoryMockDelete { if n == 0 { mmDelete.mock.t.Fatalf("Times of ThingImageRepositoryMock.Delete mock can not be zero") } mm_atomic.StoreUint64(&mmDelete.expectedInvocations, n) return mmDelete } func (mmDelete *mThingImageRepositoryMockDelete) invocationsDone() bool { if len(mmDelete.expectations) == 0 && mmDelete.defaultExpectation == nil && mmDelete.mock.funcDelete == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmDelete.mock.afterDeleteCounter) expectedInvocations := mm_atomic.LoadUint64(&mmDelete.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // Delete implements place.ThingImageRepository func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID int, tx *sql.Tx) (err error) { mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1) defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1) if mmDelete.inspectFuncDelete != nil { mmDelete.inspectFuncDelete(ctx, imageID, tx) } mm_params := ThingImageRepositoryMockDeleteParams{ctx, imageID, tx} // 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_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs mm_got := ThingImageRepositoryMockDeleteParams{ctx, imageID, tx} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { mmDelete.t.Errorf("ThingImageRepositoryMock.Delete 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)) } if mm_want_ptrs.imageID != nil && !minimock.Equal(*mm_want_ptrs.imageID, mm_got.imageID) { mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter imageID, want: %#v, got: %#v%s\n", *mm_want_ptrs.imageID, mm_got.imageID, minimock.Diff(*mm_want_ptrs.imageID, mm_got.imageID)) } if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) { mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmDelete.t.Errorf("ThingImageRepositoryMock.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 ThingImageRepositoryMock.Delete") } return (*mm_results).err } if mmDelete.funcDelete != nil { return mmDelete.funcDelete(ctx, imageID, tx) } mmDelete.t.Fatalf("Unexpected call to ThingImageRepositoryMock.Delete. %v %v %v", ctx, imageID, tx) return } // DeleteAfterCounter returns a count of finished ThingImageRepositoryMock.Delete invocations func (mmDelete *ThingImageRepositoryMock) DeleteAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmDelete.afterDeleteCounter) } // DeleteBeforeCounter returns a count of ThingImageRepositoryMock.Delete invocations func (mmDelete *ThingImageRepositoryMock) DeleteBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmDelete.beforeDeleteCounter) } // Calls returns a list of arguments used in each call to ThingImageRepositoryMock.Delete. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmDelete *mThingImageRepositoryMockDelete) Calls() []*ThingImageRepositoryMockDeleteParams { mmDelete.mutex.RLock() argCopy := make([]*ThingImageRepositoryMockDeleteParams, 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 *ThingImageRepositoryMock) MinimockDeleteDone() bool { if m.DeleteMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.DeleteMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.DeleteMock.invocationsDone() } // MinimockDeleteInspect logs each unmet expectation func (m *ThingImageRepositoryMock) MinimockDeleteInspect() { for _, e := range m.DeleteMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to ThingImageRepositoryMock.Delete with params: %#v", *e.params) } } afterDeleteCounter := mm_atomic.LoadUint64(&m.afterDeleteCounter) // if default expectation was set then invocations count should be greater than zero if m.DeleteMock.defaultExpectation != nil && afterDeleteCounter < 1 { if m.DeleteMock.defaultExpectation.params == nil { m.t.Error("Expected call to ThingImageRepositoryMock.Delete") } else { m.t.Errorf("Expected call to ThingImageRepositoryMock.Delete with params: %#v", *m.DeleteMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcDelete != nil && afterDeleteCounter < 1 { m.t.Error("Expected call to ThingImageRepositoryMock.Delete") } if !m.DeleteMock.invocationsDone() && afterDeleteCounter > 0 { m.t.Errorf("Expected %d calls to ThingImageRepositoryMock.Delete but found %d calls", mm_atomic.LoadUint64(&m.DeleteMock.expectedInvocations), afterDeleteCounter) } } type mThingImageRepositoryMockGetByThingID struct { optional bool mock *ThingImageRepositoryMock defaultExpectation *ThingImageRepositoryMockGetByThingIDExpectation expectations []*ThingImageRepositoryMockGetByThingIDExpectation callArgs []*ThingImageRepositoryMockGetByThingIDParams mutex sync.RWMutex expectedInvocations uint64 } // ThingImageRepositoryMockGetByThingIDExpectation specifies expectation struct of the ThingImageRepository.GetByThingID type ThingImageRepositoryMockGetByThingIDExpectation struct { mock *ThingImageRepositoryMock params *ThingImageRepositoryMockGetByThingIDParams paramPtrs *ThingImageRepositoryMockGetByThingIDParamPtrs results *ThingImageRepositoryMockGetByThingIDResults Counter uint64 } // ThingImageRepositoryMockGetByThingIDParams contains parameters of the ThingImageRepository.GetByThingID type ThingImageRepositoryMockGetByThingIDParams struct { ctx context.Context thingID int } // ThingImageRepositoryMockGetByThingIDParamPtrs contains pointers to parameters of the ThingImageRepository.GetByThingID type ThingImageRepositoryMockGetByThingIDParamPtrs struct { ctx *context.Context thingID *int } // ThingImageRepositoryMockGetByThingIDResults contains results of the ThingImageRepository.GetByThingID type ThingImageRepositoryMockGetByThingIDResults struct { ia1 []models.Image err error } // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning // the test will fail minimock's automatic final call check if the mocked method was not called at least once. // Optional() makes method check to work in '0 or more' mode. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to // catch the problems when the expected method call is totally skipped during test run. func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Optional() *mThingImageRepositoryMockGetByThingID { mmGetByThingID.optional = true return mmGetByThingID } // Expect sets up expected params for ThingImageRepository.GetByThingID func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Expect(ctx context.Context, thingID int) *mThingImageRepositoryMockGetByThingID { if mmGetByThingID.mock.funcGetByThingID != nil { mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set") } if mmGetByThingID.defaultExpectation == nil { mmGetByThingID.defaultExpectation = &ThingImageRepositoryMockGetByThingIDExpectation{} } if mmGetByThingID.defaultExpectation.paramPtrs != nil { mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by ExpectParams functions") } mmGetByThingID.defaultExpectation.params = &ThingImageRepositoryMockGetByThingIDParams{ctx, thingID} for _, e := range mmGetByThingID.expectations { if minimock.Equal(e.params, mmGetByThingID.defaultExpectation.params) { mmGetByThingID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetByThingID.defaultExpectation.params) } } return mmGetByThingID } // ExpectCtxParam1 sets up expected param ctx for ThingImageRepository.GetByThingID func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectCtxParam1(ctx context.Context) *mThingImageRepositoryMockGetByThingID { if mmGetByThingID.mock.funcGetByThingID != nil { mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set") } if mmGetByThingID.defaultExpectation == nil { mmGetByThingID.defaultExpectation = &ThingImageRepositoryMockGetByThingIDExpectation{} } if mmGetByThingID.defaultExpectation.params != nil { mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Expect") } if mmGetByThingID.defaultExpectation.paramPtrs == nil { mmGetByThingID.defaultExpectation.paramPtrs = &ThingImageRepositoryMockGetByThingIDParamPtrs{} } mmGetByThingID.defaultExpectation.paramPtrs.ctx = &ctx return mmGetByThingID } // ExpectThingIDParam2 sets up expected param thingID for ThingImageRepository.GetByThingID func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectThingIDParam2(thingID int) *mThingImageRepositoryMockGetByThingID { if mmGetByThingID.mock.funcGetByThingID != nil { mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set") } if mmGetByThingID.defaultExpectation == nil { mmGetByThingID.defaultExpectation = &ThingImageRepositoryMockGetByThingIDExpectation{} } if mmGetByThingID.defaultExpectation.params != nil { mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Expect") } if mmGetByThingID.defaultExpectation.paramPtrs == nil { mmGetByThingID.defaultExpectation.paramPtrs = &ThingImageRepositoryMockGetByThingIDParamPtrs{} } mmGetByThingID.defaultExpectation.paramPtrs.thingID = &thingID return mmGetByThingID } // Inspect accepts an inspector function that has same arguments as the ThingImageRepository.GetByThingID func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Inspect(f func(ctx context.Context, thingID int)) *mThingImageRepositoryMockGetByThingID { if mmGetByThingID.mock.inspectFuncGetByThingID != nil { mmGetByThingID.mock.t.Fatalf("Inspect function is already set for ThingImageRepositoryMock.GetByThingID") } mmGetByThingID.mock.inspectFuncGetByThingID = f return mmGetByThingID } // Return sets up results that will be returned by ThingImageRepository.GetByThingID func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Return(ia1 []models.Image, err error) *ThingImageRepositoryMock { if mmGetByThingID.mock.funcGetByThingID != nil { mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set") } if mmGetByThingID.defaultExpectation == nil { mmGetByThingID.defaultExpectation = &ThingImageRepositoryMockGetByThingIDExpectation{mock: mmGetByThingID.mock} } mmGetByThingID.defaultExpectation.results = &ThingImageRepositoryMockGetByThingIDResults{ia1, err} return mmGetByThingID.mock } // Set uses given function f to mock the ThingImageRepository.GetByThingID method func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Set(f func(ctx context.Context, thingID int) (ia1 []models.Image, err error)) *ThingImageRepositoryMock { if mmGetByThingID.defaultExpectation != nil { mmGetByThingID.mock.t.Fatalf("Default expectation is already set for the ThingImageRepository.GetByThingID method") } if len(mmGetByThingID.expectations) > 0 { mmGetByThingID.mock.t.Fatalf("Some expectations are already set for the ThingImageRepository.GetByThingID method") } mmGetByThingID.mock.funcGetByThingID = f return mmGetByThingID.mock } // When sets expectation for the ThingImageRepository.GetByThingID which will trigger the result defined by the following // Then helper func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) When(ctx context.Context, thingID int) *ThingImageRepositoryMockGetByThingIDExpectation { if mmGetByThingID.mock.funcGetByThingID != nil { mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set") } expectation := &ThingImageRepositoryMockGetByThingIDExpectation{ mock: mmGetByThingID.mock, params: &ThingImageRepositoryMockGetByThingIDParams{ctx, thingID}, } mmGetByThingID.expectations = append(mmGetByThingID.expectations, expectation) return expectation } // Then sets up ThingImageRepository.GetByThingID return parameters for the expectation previously defined by the When method func (e *ThingImageRepositoryMockGetByThingIDExpectation) Then(ia1 []models.Image, err error) *ThingImageRepositoryMock { e.results = &ThingImageRepositoryMockGetByThingIDResults{ia1, err} return e.mock } // Times sets number of times ThingImageRepository.GetByThingID should be invoked func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Times(n uint64) *mThingImageRepositoryMockGetByThingID { if n == 0 { mmGetByThingID.mock.t.Fatalf("Times of ThingImageRepositoryMock.GetByThingID mock can not be zero") } mm_atomic.StoreUint64(&mmGetByThingID.expectedInvocations, n) return mmGetByThingID } func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) invocationsDone() bool { if len(mmGetByThingID.expectations) == 0 && mmGetByThingID.defaultExpectation == nil && mmGetByThingID.mock.funcGetByThingID == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmGetByThingID.mock.afterGetByThingIDCounter) expectedInvocations := mm_atomic.LoadUint64(&mmGetByThingID.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // GetByThingID implements place.ThingImageRepository func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context, thingID int) (ia1 []models.Image, err error) { mm_atomic.AddUint64(&mmGetByThingID.beforeGetByThingIDCounter, 1) defer mm_atomic.AddUint64(&mmGetByThingID.afterGetByThingIDCounter, 1) if mmGetByThingID.inspectFuncGetByThingID != nil { mmGetByThingID.inspectFuncGetByThingID(ctx, thingID) } mm_params := ThingImageRepositoryMockGetByThingIDParams{ctx, thingID} // Record call args mmGetByThingID.GetByThingIDMock.mutex.Lock() mmGetByThingID.GetByThingIDMock.callArgs = append(mmGetByThingID.GetByThingIDMock.callArgs, &mm_params) mmGetByThingID.GetByThingIDMock.mutex.Unlock() for _, e := range mmGetByThingID.GetByThingIDMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.ia1, e.results.err } } if mmGetByThingID.GetByThingIDMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmGetByThingID.GetByThingIDMock.defaultExpectation.Counter, 1) mm_want := mmGetByThingID.GetByThingIDMock.defaultExpectation.params mm_want_ptrs := mmGetByThingID.GetByThingIDMock.defaultExpectation.paramPtrs mm_got := ThingImageRepositoryMockGetByThingIDParams{ctx, thingID} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID 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)) } if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) { mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmGetByThingID.GetByThingIDMock.defaultExpectation.results if mm_results == nil { mmGetByThingID.t.Fatal("No results are set for the ThingImageRepositoryMock.GetByThingID") } return (*mm_results).ia1, (*mm_results).err } if mmGetByThingID.funcGetByThingID != nil { return mmGetByThingID.funcGetByThingID(ctx, thingID) } mmGetByThingID.t.Fatalf("Unexpected call to ThingImageRepositoryMock.GetByThingID. %v %v", ctx, thingID) return } // GetByThingIDAfterCounter returns a count of finished ThingImageRepositoryMock.GetByThingID invocations func (mmGetByThingID *ThingImageRepositoryMock) GetByThingIDAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmGetByThingID.afterGetByThingIDCounter) } // GetByThingIDBeforeCounter returns a count of ThingImageRepositoryMock.GetByThingID invocations func (mmGetByThingID *ThingImageRepositoryMock) GetByThingIDBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmGetByThingID.beforeGetByThingIDCounter) } // Calls returns a list of arguments used in each call to ThingImageRepositoryMock.GetByThingID. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Calls() []*ThingImageRepositoryMockGetByThingIDParams { mmGetByThingID.mutex.RLock() argCopy := make([]*ThingImageRepositoryMockGetByThingIDParams, len(mmGetByThingID.callArgs)) copy(argCopy, mmGetByThingID.callArgs) mmGetByThingID.mutex.RUnlock() return argCopy } // MinimockGetByThingIDDone returns true if the count of the GetByThingID invocations corresponds // the number of defined expectations func (m *ThingImageRepositoryMock) MinimockGetByThingIDDone() bool { if m.GetByThingIDMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.GetByThingIDMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.GetByThingIDMock.invocationsDone() } // MinimockGetByThingIDInspect logs each unmet expectation func (m *ThingImageRepositoryMock) MinimockGetByThingIDInspect() { for _, e := range m.GetByThingIDMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to ThingImageRepositoryMock.GetByThingID with params: %#v", *e.params) } } afterGetByThingIDCounter := mm_atomic.LoadUint64(&m.afterGetByThingIDCounter) // if default expectation was set then invocations count should be greater than zero if m.GetByThingIDMock.defaultExpectation != nil && afterGetByThingIDCounter < 1 { if m.GetByThingIDMock.defaultExpectation.params == nil { m.t.Error("Expected call to ThingImageRepositoryMock.GetByThingID") } else { m.t.Errorf("Expected call to ThingImageRepositoryMock.GetByThingID with params: %#v", *m.GetByThingIDMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcGetByThingID != nil && afterGetByThingIDCounter < 1 { m.t.Error("Expected call to ThingImageRepositoryMock.GetByThingID") } if !m.GetByThingIDMock.invocationsDone() && afterGetByThingIDCounter > 0 { m.t.Errorf("Expected %d calls to ThingImageRepositoryMock.GetByThingID but found %d calls", mm_atomic.LoadUint64(&m.GetByThingIDMock.expectedInvocations), afterGetByThingIDCounter) } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *ThingImageRepositoryMock) MinimockFinish() { m.finishOnce.Do(func() { if !m.minimockDone() { m.MinimockDeleteInspect() m.MinimockGetByThingIDInspect() } }) } // MinimockWait waits for all mocked methods to be called the expected number of times func (m *ThingImageRepositoryMock) 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 *ThingImageRepositoryMock) minimockDone() bool { done := true return done && m.MinimockDeleteDone() && m.MinimockGetByThingIDDone() }