// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT. package mocks //go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place.PlaceThingRepository -o place_thing_repository_minimock.go -n PlaceThingRepositoryMock -p mocks import ( "context" "sync" mm_atomic "sync/atomic" mm_time "time" "github.com/gojuno/minimock/v3" ) // PlaceThingRepositoryMock implements place.PlaceThingRepository type PlaceThingRepositoryMock struct { t minimock.Tester finishOnce sync.Once funcDeleteThing func(ctx context.Context, id uint64) (err error) inspectFuncDeleteThing func(ctx context.Context, id uint64) afterDeleteThingCounter uint64 beforeDeleteThingCounter uint64 DeleteThingMock mPlaceThingRepositoryMockDeleteThing } // NewPlaceThingRepositoryMock returns a mock for place.PlaceThingRepository func NewPlaceThingRepositoryMock(t minimock.Tester) *PlaceThingRepositoryMock { m := &PlaceThingRepositoryMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.DeleteThingMock = mPlaceThingRepositoryMockDeleteThing{mock: m} m.DeleteThingMock.callArgs = []*PlaceThingRepositoryMockDeleteThingParams{} t.Cleanup(m.MinimockFinish) return m } type mPlaceThingRepositoryMockDeleteThing struct { optional bool mock *PlaceThingRepositoryMock defaultExpectation *PlaceThingRepositoryMockDeleteThingExpectation expectations []*PlaceThingRepositoryMockDeleteThingExpectation callArgs []*PlaceThingRepositoryMockDeleteThingParams mutex sync.RWMutex expectedInvocations uint64 } // PlaceThingRepositoryMockDeleteThingExpectation specifies expectation struct of the PlaceThingRepository.DeleteThing type PlaceThingRepositoryMockDeleteThingExpectation struct { mock *PlaceThingRepositoryMock params *PlaceThingRepositoryMockDeleteThingParams paramPtrs *PlaceThingRepositoryMockDeleteThingParamPtrs results *PlaceThingRepositoryMockDeleteThingResults Counter uint64 } // PlaceThingRepositoryMockDeleteThingParams contains parameters of the PlaceThingRepository.DeleteThing type PlaceThingRepositoryMockDeleteThingParams struct { ctx context.Context id uint64 } // PlaceThingRepositoryMockDeleteThingParamPtrs contains pointers to parameters of the PlaceThingRepository.DeleteThing type PlaceThingRepositoryMockDeleteThingParamPtrs struct { ctx *context.Context id *uint64 } // PlaceThingRepositoryMockDeleteThingResults contains results of the PlaceThingRepository.DeleteThing type PlaceThingRepositoryMockDeleteThingResults 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 (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Optional() *mPlaceThingRepositoryMockDeleteThing { mmDeleteThing.optional = true return mmDeleteThing } // Expect sets up expected params for PlaceThingRepository.DeleteThing func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Expect(ctx context.Context, id uint64) *mPlaceThingRepositoryMockDeleteThing { if mmDeleteThing.mock.funcDeleteThing != nil { mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set") } if mmDeleteThing.defaultExpectation == nil { mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{} } if mmDeleteThing.defaultExpectation.paramPtrs != nil { mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by ExpectParams functions") } mmDeleteThing.defaultExpectation.params = &PlaceThingRepositoryMockDeleteThingParams{ctx, id} for _, e := range mmDeleteThing.expectations { if minimock.Equal(e.params, mmDeleteThing.defaultExpectation.params) { mmDeleteThing.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteThing.defaultExpectation.params) } } return mmDeleteThing } // ExpectCtxParam1 sets up expected param ctx for PlaceThingRepository.DeleteThing func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectCtxParam1(ctx context.Context) *mPlaceThingRepositoryMockDeleteThing { if mmDeleteThing.mock.funcDeleteThing != nil { mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set") } if mmDeleteThing.defaultExpectation == nil { mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{} } if mmDeleteThing.defaultExpectation.params != nil { mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Expect") } if mmDeleteThing.defaultExpectation.paramPtrs == nil { mmDeleteThing.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockDeleteThingParamPtrs{} } mmDeleteThing.defaultExpectation.paramPtrs.ctx = &ctx return mmDeleteThing } // ExpectIdParam2 sets up expected param id for PlaceThingRepository.DeleteThing func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectIdParam2(id uint64) *mPlaceThingRepositoryMockDeleteThing { if mmDeleteThing.mock.funcDeleteThing != nil { mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set") } if mmDeleteThing.defaultExpectation == nil { mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{} } if mmDeleteThing.defaultExpectation.params != nil { mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Expect") } if mmDeleteThing.defaultExpectation.paramPtrs == nil { mmDeleteThing.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockDeleteThingParamPtrs{} } mmDeleteThing.defaultExpectation.paramPtrs.id = &id return mmDeleteThing } // Inspect accepts an inspector function that has same arguments as the PlaceThingRepository.DeleteThing func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Inspect(f func(ctx context.Context, id uint64)) *mPlaceThingRepositoryMockDeleteThing { if mmDeleteThing.mock.inspectFuncDeleteThing != nil { mmDeleteThing.mock.t.Fatalf("Inspect function is already set for PlaceThingRepositoryMock.DeleteThing") } mmDeleteThing.mock.inspectFuncDeleteThing = f return mmDeleteThing } // Return sets up results that will be returned by PlaceThingRepository.DeleteThing func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Return(err error) *PlaceThingRepositoryMock { if mmDeleteThing.mock.funcDeleteThing != nil { mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set") } if mmDeleteThing.defaultExpectation == nil { mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{mock: mmDeleteThing.mock} } mmDeleteThing.defaultExpectation.results = &PlaceThingRepositoryMockDeleteThingResults{err} return mmDeleteThing.mock } // Set uses given function f to mock the PlaceThingRepository.DeleteThing method func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Set(f func(ctx context.Context, id uint64) (err error)) *PlaceThingRepositoryMock { if mmDeleteThing.defaultExpectation != nil { mmDeleteThing.mock.t.Fatalf("Default expectation is already set for the PlaceThingRepository.DeleteThing method") } if len(mmDeleteThing.expectations) > 0 { mmDeleteThing.mock.t.Fatalf("Some expectations are already set for the PlaceThingRepository.DeleteThing method") } mmDeleteThing.mock.funcDeleteThing = f return mmDeleteThing.mock } // When sets expectation for the PlaceThingRepository.DeleteThing which will trigger the result defined by the following // Then helper func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) When(ctx context.Context, id uint64) *PlaceThingRepositoryMockDeleteThingExpectation { if mmDeleteThing.mock.funcDeleteThing != nil { mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set") } expectation := &PlaceThingRepositoryMockDeleteThingExpectation{ mock: mmDeleteThing.mock, params: &PlaceThingRepositoryMockDeleteThingParams{ctx, id}, } mmDeleteThing.expectations = append(mmDeleteThing.expectations, expectation) return expectation } // Then sets up PlaceThingRepository.DeleteThing return parameters for the expectation previously defined by the When method func (e *PlaceThingRepositoryMockDeleteThingExpectation) Then(err error) *PlaceThingRepositoryMock { e.results = &PlaceThingRepositoryMockDeleteThingResults{err} return e.mock } // Times sets number of times PlaceThingRepository.DeleteThing should be invoked func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Times(n uint64) *mPlaceThingRepositoryMockDeleteThing { if n == 0 { mmDeleteThing.mock.t.Fatalf("Times of PlaceThingRepositoryMock.DeleteThing mock can not be zero") } mm_atomic.StoreUint64(&mmDeleteThing.expectedInvocations, n) return mmDeleteThing } func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) invocationsDone() bool { if len(mmDeleteThing.expectations) == 0 && mmDeleteThing.defaultExpectation == nil && mmDeleteThing.mock.funcDeleteThing == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmDeleteThing.mock.afterDeleteThingCounter) expectedInvocations := mm_atomic.LoadUint64(&mmDeleteThing.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // DeleteThing implements place.PlaceThingRepository func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context, id uint64) (err error) { mm_atomic.AddUint64(&mmDeleteThing.beforeDeleteThingCounter, 1) defer mm_atomic.AddUint64(&mmDeleteThing.afterDeleteThingCounter, 1) if mmDeleteThing.inspectFuncDeleteThing != nil { mmDeleteThing.inspectFuncDeleteThing(ctx, id) } mm_params := PlaceThingRepositoryMockDeleteThingParams{ctx, id} // Record call args mmDeleteThing.DeleteThingMock.mutex.Lock() mmDeleteThing.DeleteThingMock.callArgs = append(mmDeleteThing.DeleteThingMock.callArgs, &mm_params) mmDeleteThing.DeleteThingMock.mutex.Unlock() for _, e := range mmDeleteThing.DeleteThingMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.err } } if mmDeleteThing.DeleteThingMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmDeleteThing.DeleteThingMock.defaultExpectation.Counter, 1) mm_want := mmDeleteThing.DeleteThingMock.defaultExpectation.params mm_want_ptrs := mmDeleteThing.DeleteThingMock.defaultExpectation.paramPtrs mm_got := PlaceThingRepositoryMockDeleteThingParams{ctx, id} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing 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.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) { mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmDeleteThing.DeleteThingMock.defaultExpectation.results if mm_results == nil { mmDeleteThing.t.Fatal("No results are set for the PlaceThingRepositoryMock.DeleteThing") } return (*mm_results).err } if mmDeleteThing.funcDeleteThing != nil { return mmDeleteThing.funcDeleteThing(ctx, id) } mmDeleteThing.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.DeleteThing. %v %v", ctx, id) return } // DeleteThingAfterCounter returns a count of finished PlaceThingRepositoryMock.DeleteThing invocations func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThingAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmDeleteThing.afterDeleteThingCounter) } // DeleteThingBeforeCounter returns a count of PlaceThingRepositoryMock.DeleteThing invocations func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThingBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmDeleteThing.beforeDeleteThingCounter) } // Calls returns a list of arguments used in each call to PlaceThingRepositoryMock.DeleteThing. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Calls() []*PlaceThingRepositoryMockDeleteThingParams { mmDeleteThing.mutex.RLock() argCopy := make([]*PlaceThingRepositoryMockDeleteThingParams, len(mmDeleteThing.callArgs)) copy(argCopy, mmDeleteThing.callArgs) mmDeleteThing.mutex.RUnlock() return argCopy } // MinimockDeleteThingDone returns true if the count of the DeleteThing invocations corresponds // the number of defined expectations func (m *PlaceThingRepositoryMock) MinimockDeleteThingDone() bool { if m.DeleteThingMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.DeleteThingMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.DeleteThingMock.invocationsDone() } // MinimockDeleteThingInspect logs each unmet expectation func (m *PlaceThingRepositoryMock) MinimockDeleteThingInspect() { for _, e := range m.DeleteThingMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to PlaceThingRepositoryMock.DeleteThing with params: %#v", *e.params) } } afterDeleteThingCounter := mm_atomic.LoadUint64(&m.afterDeleteThingCounter) // if default expectation was set then invocations count should be greater than zero if m.DeleteThingMock.defaultExpectation != nil && afterDeleteThingCounter < 1 { if m.DeleteThingMock.defaultExpectation.params == nil { m.t.Error("Expected call to PlaceThingRepositoryMock.DeleteThing") } else { m.t.Errorf("Expected call to PlaceThingRepositoryMock.DeleteThing with params: %#v", *m.DeleteThingMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcDeleteThing != nil && afterDeleteThingCounter < 1 { m.t.Error("Expected call to PlaceThingRepositoryMock.DeleteThing") } if !m.DeleteThingMock.invocationsDone() && afterDeleteThingCounter > 0 { m.t.Errorf("Expected %d calls to PlaceThingRepositoryMock.DeleteThing but found %d calls", mm_atomic.LoadUint64(&m.DeleteThingMock.expectedInvocations), afterDeleteThingCounter) } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *PlaceThingRepositoryMock) MinimockFinish() { m.finishOnce.Do(func() { if !m.minimockDone() { m.MinimockDeleteThingInspect() } }) } // MinimockWait waits for all mocked methods to be called the expected number of times func (m *PlaceThingRepositoryMock) 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 *PlaceThingRepositoryMock) minimockDone() bool { done := true return done && m.MinimockDeleteThingDone() }