package mocks // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. //go:generate minimock -i github.com/dmitriygnatenko/internal/interfaces.ICache -o ./mocks/i_cache_minimock.go -n ICacheMock import ( "sync" mm_atomic "sync/atomic" mm_time "time" "github.com/gojuno/minimock/v3" ) // ICacheMock implements interfaces.ICache type ICacheMock struct { t minimock.Tester funcFlushAll func() inspectFuncFlushAll func() afterFlushAllCounter uint64 beforeFlushAllCounter uint64 FlushAllMock mICacheMockFlushAll funcGet func(key string) (p1 interface{}, b1 bool) inspectFuncGet func(key string) afterGetCounter uint64 beforeGetCounter uint64 GetMock mICacheMockGet funcSet func(key string, value interface{}) inspectFuncSet func(key string, value interface{}) afterSetCounter uint64 beforeSetCounter uint64 SetMock mICacheMockSet } // NewICacheMock returns a mock for interfaces.ICache func NewICacheMock(t minimock.Tester) *ICacheMock { m := &ICacheMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.FlushAllMock = mICacheMockFlushAll{mock: m} m.GetMock = mICacheMockGet{mock: m} m.GetMock.callArgs = []*ICacheMockGetParams{} m.SetMock = mICacheMockSet{mock: m} m.SetMock.callArgs = []*ICacheMockSetParams{} return m } type mICacheMockFlushAll struct { mock *ICacheMock defaultExpectation *ICacheMockFlushAllExpectation expectations []*ICacheMockFlushAllExpectation } // ICacheMockFlushAllExpectation specifies expectation struct of the ICache.FlushAll type ICacheMockFlushAllExpectation struct { mock *ICacheMock Counter uint64 } // Expect sets up expected params for ICache.FlushAll func (mmFlushAll *mICacheMockFlushAll) Expect() *mICacheMockFlushAll { if mmFlushAll.mock.funcFlushAll != nil { mmFlushAll.mock.t.Fatalf("ICacheMock.FlushAll mock is already set by Set") } if mmFlushAll.defaultExpectation == nil { mmFlushAll.defaultExpectation = &ICacheMockFlushAllExpectation{} } return mmFlushAll } // Inspect accepts an inspector function that has same arguments as the ICache.FlushAll func (mmFlushAll *mICacheMockFlushAll) Inspect(f func()) *mICacheMockFlushAll { if mmFlushAll.mock.inspectFuncFlushAll != nil { mmFlushAll.mock.t.Fatalf("Inspect function is already set for ICacheMock.FlushAll") } mmFlushAll.mock.inspectFuncFlushAll = f return mmFlushAll } // Return sets up results that will be returned by ICache.FlushAll func (mmFlushAll *mICacheMockFlushAll) Return() *ICacheMock { if mmFlushAll.mock.funcFlushAll != nil { mmFlushAll.mock.t.Fatalf("ICacheMock.FlushAll mock is already set by Set") } if mmFlushAll.defaultExpectation == nil { mmFlushAll.defaultExpectation = &ICacheMockFlushAllExpectation{mock: mmFlushAll.mock} } return mmFlushAll.mock } //Set uses given function f to mock the ICache.FlushAll method func (mmFlushAll *mICacheMockFlushAll) Set(f func()) *ICacheMock { if mmFlushAll.defaultExpectation != nil { mmFlushAll.mock.t.Fatalf("Default expectation is already set for the ICache.FlushAll method") } if len(mmFlushAll.expectations) > 0 { mmFlushAll.mock.t.Fatalf("Some expectations are already set for the ICache.FlushAll method") } mmFlushAll.mock.funcFlushAll = f return mmFlushAll.mock } // FlushAll implements interfaces.ICache func (mmFlushAll *ICacheMock) FlushAll() { mm_atomic.AddUint64(&mmFlushAll.beforeFlushAllCounter, 1) defer mm_atomic.AddUint64(&mmFlushAll.afterFlushAllCounter, 1) if mmFlushAll.inspectFuncFlushAll != nil { mmFlushAll.inspectFuncFlushAll() } if mmFlushAll.FlushAllMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmFlushAll.FlushAllMock.defaultExpectation.Counter, 1) return } if mmFlushAll.funcFlushAll != nil { mmFlushAll.funcFlushAll() return } mmFlushAll.t.Fatalf("Unexpected call to ICacheMock.FlushAll.") } // FlushAllAfterCounter returns a count of finished ICacheMock.FlushAll invocations func (mmFlushAll *ICacheMock) FlushAllAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmFlushAll.afterFlushAllCounter) } // FlushAllBeforeCounter returns a count of ICacheMock.FlushAll invocations func (mmFlushAll *ICacheMock) FlushAllBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmFlushAll.beforeFlushAllCounter) } // MinimockFlushAllDone returns true if the count of the FlushAll invocations corresponds // the number of defined expectations func (m *ICacheMock) MinimockFlushAllDone() bool { for _, e := range m.FlushAllMock.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.FlushAllMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFlushAllCounter) < 1 { return false } // if func was set then invocations count should be greater than zero if m.funcFlushAll != nil && mm_atomic.LoadUint64(&m.afterFlushAllCounter) < 1 { return false } return true } // MinimockFlushAllInspect logs each unmet expectation func (m *ICacheMock) MinimockFlushAllInspect() { for _, e := range m.FlushAllMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Error("Expected call to ICacheMock.FlushAll") } } // if default expectation was set then invocations count should be greater than zero if m.FlushAllMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFlushAllCounter) < 1 { m.t.Error("Expected call to ICacheMock.FlushAll") } // if func was set then invocations count should be greater than zero if m.funcFlushAll != nil && mm_atomic.LoadUint64(&m.afterFlushAllCounter) < 1 { m.t.Error("Expected call to ICacheMock.FlushAll") } } type mICacheMockGet struct { mock *ICacheMock defaultExpectation *ICacheMockGetExpectation expectations []*ICacheMockGetExpectation callArgs []*ICacheMockGetParams mutex sync.RWMutex } // ICacheMockGetExpectation specifies expectation struct of the ICache.Get type ICacheMockGetExpectation struct { mock *ICacheMock params *ICacheMockGetParams results *ICacheMockGetResults Counter uint64 } // ICacheMockGetParams contains parameters of the ICache.Get type ICacheMockGetParams struct { key string } // ICacheMockGetResults contains results of the ICache.Get type ICacheMockGetResults struct { p1 interface{} b1 bool } // Expect sets up expected params for ICache.Get func (mmGet *mICacheMockGet) Expect(key string) *mICacheMockGet { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("ICacheMock.Get mock is already set by Set") } if mmGet.defaultExpectation == nil { mmGet.defaultExpectation = &ICacheMockGetExpectation{} } mmGet.defaultExpectation.params = &ICacheMockGetParams{key} for _, e := range mmGet.expectations { if minimock.Equal(e.params, mmGet.defaultExpectation.params) { mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params) } } return mmGet } // Inspect accepts an inspector function that has same arguments as the ICache.Get func (mmGet *mICacheMockGet) Inspect(f func(key string)) *mICacheMockGet { if mmGet.mock.inspectFuncGet != nil { mmGet.mock.t.Fatalf("Inspect function is already set for ICacheMock.Get") } mmGet.mock.inspectFuncGet = f return mmGet } // Return sets up results that will be returned by ICache.Get func (mmGet *mICacheMockGet) Return(p1 interface{}, b1 bool) *ICacheMock { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("ICacheMock.Get mock is already set by Set") } if mmGet.defaultExpectation == nil { mmGet.defaultExpectation = &ICacheMockGetExpectation{mock: mmGet.mock} } mmGet.defaultExpectation.results = &ICacheMockGetResults{p1, b1} return mmGet.mock } //Set uses given function f to mock the ICache.Get method func (mmGet *mICacheMockGet) Set(f func(key string) (p1 interface{}, b1 bool)) *ICacheMock { if mmGet.defaultExpectation != nil { mmGet.mock.t.Fatalf("Default expectation is already set for the ICache.Get method") } if len(mmGet.expectations) > 0 { mmGet.mock.t.Fatalf("Some expectations are already set for the ICache.Get method") } mmGet.mock.funcGet = f return mmGet.mock } // When sets expectation for the ICache.Get which will trigger the result defined by the following // Then helper func (mmGet *mICacheMockGet) When(key string) *ICacheMockGetExpectation { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("ICacheMock.Get mock is already set by Set") } expectation := &ICacheMockGetExpectation{ mock: mmGet.mock, params: &ICacheMockGetParams{key}, } mmGet.expectations = append(mmGet.expectations, expectation) return expectation } // Then sets up ICache.Get return parameters for the expectation previously defined by the When method func (e *ICacheMockGetExpectation) Then(p1 interface{}, b1 bool) *ICacheMock { e.results = &ICacheMockGetResults{p1, b1} return e.mock } // Get implements interfaces.ICache func (mmGet *ICacheMock) Get(key string) (p1 interface{}, b1 bool) { mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1) defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1) if mmGet.inspectFuncGet != nil { mmGet.inspectFuncGet(key) } mm_params := &ICacheMockGetParams{key} // Record call args mmGet.GetMock.mutex.Lock() mmGet.GetMock.callArgs = append(mmGet.GetMock.callArgs, mm_params) mmGet.GetMock.mutex.Unlock() for _, e := range mmGet.GetMock.expectations { if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.p1, e.results.b1 } } if mmGet.GetMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmGet.GetMock.defaultExpectation.Counter, 1) mm_want := mmGet.GetMock.defaultExpectation.params mm_got := ICacheMockGetParams{key} if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmGet.t.Errorf("ICacheMock.Get got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmGet.GetMock.defaultExpectation.results if mm_results == nil { mmGet.t.Fatal("No results are set for the ICacheMock.Get") } return (*mm_results).p1, (*mm_results).b1 } if mmGet.funcGet != nil { return mmGet.funcGet(key) } mmGet.t.Fatalf("Unexpected call to ICacheMock.Get. %v", key) return } // GetAfterCounter returns a count of finished ICacheMock.Get invocations func (mmGet *ICacheMock) GetAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmGet.afterGetCounter) } // GetBeforeCounter returns a count of ICacheMock.Get invocations func (mmGet *ICacheMock) GetBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmGet.beforeGetCounter) } // Calls returns a list of arguments used in each call to ICacheMock.Get. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmGet *mICacheMockGet) Calls() []*ICacheMockGetParams { mmGet.mutex.RLock() argCopy := make([]*ICacheMockGetParams, len(mmGet.callArgs)) copy(argCopy, mmGet.callArgs) mmGet.mutex.RUnlock() return argCopy } // MinimockGetDone returns true if the count of the Get invocations corresponds // the number of defined expectations func (m *ICacheMock) MinimockGetDone() bool { for _, e := range m.GetMock.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.GetMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 { return false } // if func was set then invocations count should be greater than zero if m.funcGet != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 { return false } return true } // MinimockGetInspect logs each unmet expectation func (m *ICacheMock) MinimockGetInspect() { for _, e := range m.GetMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to ICacheMock.Get with params: %#v", *e.params) } } // if default expectation was set then invocations count should be greater than zero if m.GetMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 { if m.GetMock.defaultExpectation.params == nil { m.t.Error("Expected call to ICacheMock.Get") } else { m.t.Errorf("Expected call to ICacheMock.Get with params: %#v", *m.GetMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcGet != nil && mm_atomic.LoadUint64(&m.afterGetCounter) < 1 { m.t.Error("Expected call to ICacheMock.Get") } } type mICacheMockSet struct { mock *ICacheMock defaultExpectation *ICacheMockSetExpectation expectations []*ICacheMockSetExpectation callArgs []*ICacheMockSetParams mutex sync.RWMutex } // ICacheMockSetExpectation specifies expectation struct of the ICache.Set type ICacheMockSetExpectation struct { mock *ICacheMock params *ICacheMockSetParams Counter uint64 } // ICacheMockSetParams contains parameters of the ICache.Set type ICacheMockSetParams struct { key string value interface{} } // Expect sets up expected params for ICache.Set func (mmSet *mICacheMockSet) Expect(key string, value interface{}) *mICacheMockSet { if mmSet.mock.funcSet != nil { mmSet.mock.t.Fatalf("ICacheMock.Set mock is already set by Set") } if mmSet.defaultExpectation == nil { mmSet.defaultExpectation = &ICacheMockSetExpectation{} } mmSet.defaultExpectation.params = &ICacheMockSetParams{key, value} for _, e := range mmSet.expectations { if minimock.Equal(e.params, mmSet.defaultExpectation.params) { mmSet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmSet.defaultExpectation.params) } } return mmSet } // Inspect accepts an inspector function that has same arguments as the ICache.Set func (mmSet *mICacheMockSet) Inspect(f func(key string, value interface{})) *mICacheMockSet { if mmSet.mock.inspectFuncSet != nil { mmSet.mock.t.Fatalf("Inspect function is already set for ICacheMock.Set") } mmSet.mock.inspectFuncSet = f return mmSet } // Return sets up results that will be returned by ICache.Set func (mmSet *mICacheMockSet) Return() *ICacheMock { if mmSet.mock.funcSet != nil { mmSet.mock.t.Fatalf("ICacheMock.Set mock is already set by Set") } if mmSet.defaultExpectation == nil { mmSet.defaultExpectation = &ICacheMockSetExpectation{mock: mmSet.mock} } return mmSet.mock } //Set uses given function f to mock the ICache.Set method func (mmSet *mICacheMockSet) Set(f func(key string, value interface{})) *ICacheMock { if mmSet.defaultExpectation != nil { mmSet.mock.t.Fatalf("Default expectation is already set for the ICache.Set method") } if len(mmSet.expectations) > 0 { mmSet.mock.t.Fatalf("Some expectations are already set for the ICache.Set method") } mmSet.mock.funcSet = f return mmSet.mock } // Set implements interfaces.ICache func (mmSet *ICacheMock) Set(key string, value interface{}) { mm_atomic.AddUint64(&mmSet.beforeSetCounter, 1) defer mm_atomic.AddUint64(&mmSet.afterSetCounter, 1) if mmSet.inspectFuncSet != nil { mmSet.inspectFuncSet(key, value) } mm_params := &ICacheMockSetParams{key, value} // Record call args mmSet.SetMock.mutex.Lock() mmSet.SetMock.callArgs = append(mmSet.SetMock.callArgs, mm_params) mmSet.SetMock.mutex.Unlock() for _, e := range mmSet.SetMock.expectations { if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return } } if mmSet.SetMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmSet.SetMock.defaultExpectation.Counter, 1) mm_want := mmSet.SetMock.defaultExpectation.params mm_got := ICacheMockSetParams{key, value} if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmSet.t.Errorf("ICacheMock.Set got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } return } if mmSet.funcSet != nil { mmSet.funcSet(key, value) return } mmSet.t.Fatalf("Unexpected call to ICacheMock.Set. %v %v", key, value) } // SetAfterCounter returns a count of finished ICacheMock.Set invocations func (mmSet *ICacheMock) SetAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmSet.afterSetCounter) } // SetBeforeCounter returns a count of ICacheMock.Set invocations func (mmSet *ICacheMock) SetBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmSet.beforeSetCounter) } // Calls returns a list of arguments used in each call to ICacheMock.Set. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmSet *mICacheMockSet) Calls() []*ICacheMockSetParams { mmSet.mutex.RLock() argCopy := make([]*ICacheMockSetParams, len(mmSet.callArgs)) copy(argCopy, mmSet.callArgs) mmSet.mutex.RUnlock() return argCopy } // MinimockSetDone returns true if the count of the Set invocations corresponds // the number of defined expectations func (m *ICacheMock) MinimockSetDone() bool { for _, e := range m.SetMock.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.SetMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterSetCounter) < 1 { return false } // if func was set then invocations count should be greater than zero if m.funcSet != nil && mm_atomic.LoadUint64(&m.afterSetCounter) < 1 { return false } return true } // MinimockSetInspect logs each unmet expectation func (m *ICacheMock) MinimockSetInspect() { for _, e := range m.SetMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to ICacheMock.Set with params: %#v", *e.params) } } // if default expectation was set then invocations count should be greater than zero if m.SetMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterSetCounter) < 1 { if m.SetMock.defaultExpectation.params == nil { m.t.Error("Expected call to ICacheMock.Set") } else { m.t.Errorf("Expected call to ICacheMock.Set with params: %#v", *m.SetMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcSet != nil && mm_atomic.LoadUint64(&m.afterSetCounter) < 1 { m.t.Error("Expected call to ICacheMock.Set") } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *ICacheMock) MinimockFinish() { if !m.minimockDone() { m.MinimockFlushAllInspect() m.MinimockGetInspect() m.MinimockSetInspect() m.t.FailNow() } } // MinimockWait waits for all mocked methods to be called the expected number of times func (m *ICacheMock) 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 *ICacheMock) minimockDone() bool { done := true return done && m.MinimockFlushAllDone() && m.MinimockGetDone() && m.MinimockSetDone() }