123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- // 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/image.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 image.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 image.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 image.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()
- }
|