// 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/thing.TransactionManager -o transaction_manager_minimock.go -n TransactionManagerMock -p mocks import ( "context" "sync" mm_atomic "sync/atomic" mm_time "time" "github.com/gojuno/minimock/v3" ) // TransactionManagerMock implements thing.TransactionManager type TransactionManagerMock struct { t minimock.Tester finishOnce sync.Once funcReadCommitted func(ctx context.Context, f1 func(ctx context.Context) error) (err error) inspectFuncReadCommitted func(ctx context.Context, f1 func(ctx context.Context) error) afterReadCommittedCounter uint64 beforeReadCommittedCounter uint64 ReadCommittedMock mTransactionManagerMockReadCommitted } // NewTransactionManagerMock returns a mock for thing.TransactionManager func NewTransactionManagerMock(t minimock.Tester) *TransactionManagerMock { m := &TransactionManagerMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.ReadCommittedMock = mTransactionManagerMockReadCommitted{mock: m} m.ReadCommittedMock.callArgs = []*TransactionManagerMockReadCommittedParams{} t.Cleanup(m.MinimockFinish) return m } type mTransactionManagerMockReadCommitted struct { optional bool mock *TransactionManagerMock defaultExpectation *TransactionManagerMockReadCommittedExpectation expectations []*TransactionManagerMockReadCommittedExpectation callArgs []*TransactionManagerMockReadCommittedParams mutex sync.RWMutex expectedInvocations uint64 } // TransactionManagerMockReadCommittedExpectation specifies expectation struct of the TransactionManager.ReadCommitted type TransactionManagerMockReadCommittedExpectation struct { mock *TransactionManagerMock params *TransactionManagerMockReadCommittedParams paramPtrs *TransactionManagerMockReadCommittedParamPtrs results *TransactionManagerMockReadCommittedResults Counter uint64 } // TransactionManagerMockReadCommittedParams contains parameters of the TransactionManager.ReadCommitted type TransactionManagerMockReadCommittedParams struct { ctx context.Context f1 func(ctx context.Context) error } // TransactionManagerMockReadCommittedParamPtrs contains pointers to parameters of the TransactionManager.ReadCommitted type TransactionManagerMockReadCommittedParamPtrs struct { ctx *context.Context f1 *func(ctx context.Context) error } // TransactionManagerMockReadCommittedResults contains results of the TransactionManager.ReadCommitted type TransactionManagerMockReadCommittedResults 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 (mmReadCommitted *mTransactionManagerMockReadCommitted) Optional() *mTransactionManagerMockReadCommitted { mmReadCommitted.optional = true return mmReadCommitted } // Expect sets up expected params for TransactionManager.ReadCommitted func (mmReadCommitted *mTransactionManagerMockReadCommitted) Expect(ctx context.Context, f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted { if mmReadCommitted.mock.funcReadCommitted != nil { mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set") } if mmReadCommitted.defaultExpectation == nil { mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{} } if mmReadCommitted.defaultExpectation.paramPtrs != nil { mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by ExpectParams functions") } mmReadCommitted.defaultExpectation.params = &TransactionManagerMockReadCommittedParams{ctx, f1} for _, e := range mmReadCommitted.expectations { if minimock.Equal(e.params, mmReadCommitted.defaultExpectation.params) { mmReadCommitted.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmReadCommitted.defaultExpectation.params) } } return mmReadCommitted } // ExpectCtxParam1 sets up expected param ctx for TransactionManager.ReadCommitted func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectCtxParam1(ctx context.Context) *mTransactionManagerMockReadCommitted { if mmReadCommitted.mock.funcReadCommitted != nil { mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set") } if mmReadCommitted.defaultExpectation == nil { mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{} } if mmReadCommitted.defaultExpectation.params != nil { mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect") } if mmReadCommitted.defaultExpectation.paramPtrs == nil { mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{} } mmReadCommitted.defaultExpectation.paramPtrs.ctx = &ctx return mmReadCommitted } // ExpectF1Param2 sets up expected param f1 for TransactionManager.ReadCommitted func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectF1Param2(f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted { if mmReadCommitted.mock.funcReadCommitted != nil { mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set") } if mmReadCommitted.defaultExpectation == nil { mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{} } if mmReadCommitted.defaultExpectation.params != nil { mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect") } if mmReadCommitted.defaultExpectation.paramPtrs == nil { mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{} } mmReadCommitted.defaultExpectation.paramPtrs.f1 = &f1 return mmReadCommitted } // Inspect accepts an inspector function that has same arguments as the TransactionManager.ReadCommitted func (mmReadCommitted *mTransactionManagerMockReadCommitted) Inspect(f func(ctx context.Context, f1 func(ctx context.Context) error)) *mTransactionManagerMockReadCommitted { if mmReadCommitted.mock.inspectFuncReadCommitted != nil { mmReadCommitted.mock.t.Fatalf("Inspect function is already set for TransactionManagerMock.ReadCommitted") } mmReadCommitted.mock.inspectFuncReadCommitted = f return mmReadCommitted } // Return sets up results that will be returned by TransactionManager.ReadCommitted func (mmReadCommitted *mTransactionManagerMockReadCommitted) Return(err error) *TransactionManagerMock { if mmReadCommitted.mock.funcReadCommitted != nil { mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set") } if mmReadCommitted.defaultExpectation == nil { mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{mock: mmReadCommitted.mock} } mmReadCommitted.defaultExpectation.results = &TransactionManagerMockReadCommittedResults{err} return mmReadCommitted.mock } // Set uses given function f to mock the TransactionManager.ReadCommitted method func (mmReadCommitted *mTransactionManagerMockReadCommitted) Set(f func(ctx context.Context, f1 func(ctx context.Context) error) (err error)) *TransactionManagerMock { if mmReadCommitted.defaultExpectation != nil { mmReadCommitted.mock.t.Fatalf("Default expectation is already set for the TransactionManager.ReadCommitted method") } if len(mmReadCommitted.expectations) > 0 { mmReadCommitted.mock.t.Fatalf("Some expectations are already set for the TransactionManager.ReadCommitted method") } mmReadCommitted.mock.funcReadCommitted = f return mmReadCommitted.mock } // When sets expectation for the TransactionManager.ReadCommitted which will trigger the result defined by the following // Then helper func (mmReadCommitted *mTransactionManagerMockReadCommitted) When(ctx context.Context, f1 func(ctx context.Context) error) *TransactionManagerMockReadCommittedExpectation { if mmReadCommitted.mock.funcReadCommitted != nil { mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set") } expectation := &TransactionManagerMockReadCommittedExpectation{ mock: mmReadCommitted.mock, params: &TransactionManagerMockReadCommittedParams{ctx, f1}, } mmReadCommitted.expectations = append(mmReadCommitted.expectations, expectation) return expectation } // Then sets up TransactionManager.ReadCommitted return parameters for the expectation previously defined by the When method func (e *TransactionManagerMockReadCommittedExpectation) Then(err error) *TransactionManagerMock { e.results = &TransactionManagerMockReadCommittedResults{err} return e.mock } // Times sets number of times TransactionManager.ReadCommitted should be invoked func (mmReadCommitted *mTransactionManagerMockReadCommitted) Times(n uint64) *mTransactionManagerMockReadCommitted { if n == 0 { mmReadCommitted.mock.t.Fatalf("Times of TransactionManagerMock.ReadCommitted mock can not be zero") } mm_atomic.StoreUint64(&mmReadCommitted.expectedInvocations, n) return mmReadCommitted } func (mmReadCommitted *mTransactionManagerMockReadCommitted) invocationsDone() bool { if len(mmReadCommitted.expectations) == 0 && mmReadCommitted.defaultExpectation == nil && mmReadCommitted.mock.funcReadCommitted == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmReadCommitted.mock.afterReadCommittedCounter) expectedInvocations := mm_atomic.LoadUint64(&mmReadCommitted.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // ReadCommitted implements thing.TransactionManager func (mmReadCommitted *TransactionManagerMock) ReadCommitted(ctx context.Context, f1 func(ctx context.Context) error) (err error) { mm_atomic.AddUint64(&mmReadCommitted.beforeReadCommittedCounter, 1) defer mm_atomic.AddUint64(&mmReadCommitted.afterReadCommittedCounter, 1) if mmReadCommitted.inspectFuncReadCommitted != nil { mmReadCommitted.inspectFuncReadCommitted(ctx, f1) } mm_params := TransactionManagerMockReadCommittedParams{ctx, f1} // Record call args mmReadCommitted.ReadCommittedMock.mutex.Lock() mmReadCommitted.ReadCommittedMock.callArgs = append(mmReadCommitted.ReadCommittedMock.callArgs, &mm_params) mmReadCommitted.ReadCommittedMock.mutex.Unlock() for _, e := range mmReadCommitted.ReadCommittedMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.err } } if mmReadCommitted.ReadCommittedMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmReadCommitted.ReadCommittedMock.defaultExpectation.Counter, 1) mm_want := mmReadCommitted.ReadCommittedMock.defaultExpectation.params mm_want_ptrs := mmReadCommitted.ReadCommittedMock.defaultExpectation.paramPtrs mm_got := TransactionManagerMockReadCommittedParams{ctx, f1} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted 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.f1 != nil && !minimock.Equal(*mm_want_ptrs.f1, mm_got.f1) { mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter f1, want: %#v, got: %#v%s\n", *mm_want_ptrs.f1, mm_got.f1, minimock.Diff(*mm_want_ptrs.f1, mm_got.f1)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmReadCommitted.ReadCommittedMock.defaultExpectation.results if mm_results == nil { mmReadCommitted.t.Fatal("No results are set for the TransactionManagerMock.ReadCommitted") } return (*mm_results).err } if mmReadCommitted.funcReadCommitted != nil { return mmReadCommitted.funcReadCommitted(ctx, f1) } mmReadCommitted.t.Fatalf("Unexpected call to TransactionManagerMock.ReadCommitted. %v %v", ctx, f1) return } // ReadCommittedAfterCounter returns a count of finished TransactionManagerMock.ReadCommitted invocations func (mmReadCommitted *TransactionManagerMock) ReadCommittedAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmReadCommitted.afterReadCommittedCounter) } // ReadCommittedBeforeCounter returns a count of TransactionManagerMock.ReadCommitted invocations func (mmReadCommitted *TransactionManagerMock) ReadCommittedBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmReadCommitted.beforeReadCommittedCounter) } // Calls returns a list of arguments used in each call to TransactionManagerMock.ReadCommitted. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmReadCommitted *mTransactionManagerMockReadCommitted) Calls() []*TransactionManagerMockReadCommittedParams { mmReadCommitted.mutex.RLock() argCopy := make([]*TransactionManagerMockReadCommittedParams, len(mmReadCommitted.callArgs)) copy(argCopy, mmReadCommitted.callArgs) mmReadCommitted.mutex.RUnlock() return argCopy } // MinimockReadCommittedDone returns true if the count of the ReadCommitted invocations corresponds // the number of defined expectations func (m *TransactionManagerMock) MinimockReadCommittedDone() bool { if m.ReadCommittedMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.ReadCommittedMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.ReadCommittedMock.invocationsDone() } // MinimockReadCommittedInspect logs each unmet expectation func (m *TransactionManagerMock) MinimockReadCommittedInspect() { for _, e := range m.ReadCommittedMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *e.params) } } afterReadCommittedCounter := mm_atomic.LoadUint64(&m.afterReadCommittedCounter) // if default expectation was set then invocations count should be greater than zero if m.ReadCommittedMock.defaultExpectation != nil && afterReadCommittedCounter < 1 { if m.ReadCommittedMock.defaultExpectation.params == nil { m.t.Error("Expected call to TransactionManagerMock.ReadCommitted") } else { m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *m.ReadCommittedMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcReadCommitted != nil && afterReadCommittedCounter < 1 { m.t.Error("Expected call to TransactionManagerMock.ReadCommitted") } if !m.ReadCommittedMock.invocationsDone() && afterReadCommittedCounter > 0 { m.t.Errorf("Expected %d calls to TransactionManagerMock.ReadCommitted but found %d calls", mm_atomic.LoadUint64(&m.ReadCommittedMock.expectedInvocations), afterReadCommittedCounter) } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *TransactionManagerMock) MinimockFinish() { m.finishOnce.Do(func() { if !m.minimockDone() { m.MinimockReadCommittedInspect() } }) } // MinimockWait waits for all mocked methods to be called the expected number of times func (m *TransactionManagerMock) 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 *TransactionManagerMock) minimockDone() bool { done := true return done && m.MinimockReadCommittedDone() }