package mocks // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. //go:generate minimock -i github.com/dmitriygnatenko/internal/interfaces.Cache -o ./mocks/cache_minimock.go -n CacheMock import ( "sync" mm_atomic "sync/atomic" mm_time "time" "github.com/gojuno/minimock/v3" ) // CacheMock implements interfaces.Cache type CacheMock struct { t minimock.Tester funcFlushAll func() inspectFuncFlushAll func() afterFlushAllCounter uint64 beforeFlushAllCounter uint64 FlushAllMock mCacheMockFlushAll funcGet func(key string) (p1 interface{}, b1 bool) inspectFuncGet func(key string) afterGetCounter uint64 beforeGetCounter uint64 GetMock mCacheMockGet funcSet func(key string, value interface{}) inspectFuncSet func(key string, value interface{}) afterSetCounter uint64 beforeSetCounter uint64 SetMock mCacheMockSet } // NewCacheMock returns a mock for interfaces.Cache func NewCacheMock(t minimock.Tester) *CacheMock { m := &CacheMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.FlushAllMock = mCacheMockFlushAll{mock: m} m.GetMock = mCacheMockGet{mock: m} m.GetMock.callArgs = []*CacheMockGetParams{} m.SetMock = mCacheMockSet{mock: m} m.SetMock.callArgs = []*CacheMockSetParams{} return m } type mCacheMockFlushAll struct { mock *CacheMock defaultExpectation *CacheMockFlushAllExpectation expectations []*CacheMockFlushAllExpectation } // CacheMockFlushAllExpectation specifies expectation struct of the Cache.FlushAll type CacheMockFlushAllExpectation struct { mock *CacheMock Counter uint64 } // Expect sets up expected params for Cache.FlushAll func (mmFlushAll *mCacheMockFlushAll) Expect() *mCacheMockFlushAll { if mmFlushAll.mock.funcFlushAll != nil { mmFlushAll.mock.t.Fatalf("CacheMock.FlushAll mock is already set by Set") } if mmFlushAll.defaultExpectation == nil { mmFlushAll.defaultExpectation = &CacheMockFlushAllExpectation{} } return mmFlushAll } // Inspect accepts an inspector function that has same arguments as the Cache.FlushAll func (mmFlushAll *mCacheMockFlushAll) Inspect(f func()) *mCacheMockFlushAll { if mmFlushAll.mock.inspectFuncFlushAll != nil { mmFlushAll.mock.t.Fatalf("Inspect function is already set for CacheMock.FlushAll") } mmFlushAll.mock.inspectFuncFlushAll = f return mmFlushAll } // Return sets up results that will be returned by Cache.FlushAll func (mmFlushAll *mCacheMockFlushAll) Return() *CacheMock { if mmFlushAll.mock.funcFlushAll != nil { mmFlushAll.mock.t.Fatalf("CacheMock.FlushAll mock is already set by Set") } if mmFlushAll.defaultExpectation == nil { mmFlushAll.defaultExpectation = &CacheMockFlushAllExpectation{mock: mmFlushAll.mock} } return mmFlushAll.mock } // Set uses given function f to mock the Cache.FlushAll method func (mmFlushAll *mCacheMockFlushAll) Set(f func()) *CacheMock { if mmFlushAll.defaultExpectation != nil { mmFlushAll.mock.t.Fatalf("Default expectation is already set for the Cache.FlushAll method") } if len(mmFlushAll.expectations) > 0 { mmFlushAll.mock.t.Fatalf("Some expectations are already set for the Cache.FlushAll method") } mmFlushAll.mock.funcFlushAll = f return mmFlushAll.mock } // FlushAll implements interfaces.Cache func (mmFlushAll *CacheMock) 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 CacheMock.FlushAll.") } // FlushAllAfterCounter returns a count of finished CacheMock.FlushAll invocations func (mmFlushAll *CacheMock) FlushAllAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmFlushAll.afterFlushAllCounter) } // FlushAllBeforeCounter returns a count of CacheMock.FlushAll invocations func (mmFlushAll *CacheMock) 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 *CacheMock) 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 *CacheMock) MinimockFlushAllInspect() { for _, e := range m.FlushAllMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Error("Expected call to CacheMock.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 CacheMock.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 CacheMock.FlushAll") } } type mCacheMockGet struct { mock *CacheMock defaultExpectation *CacheMockGetExpectation expectations []*CacheMockGetExpectation callArgs []*CacheMockGetParams mutex sync.RWMutex } // CacheMockGetExpectation specifies expectation struct of the Cache.Get type CacheMockGetExpectation struct { mock *CacheMock params *CacheMockGetParams results *CacheMockGetResults Counter uint64 } // CacheMockGetParams contains parameters of the Cache.Get type CacheMockGetParams struct { key string } // CacheMockGetResults contains results of the Cache.Get type CacheMockGetResults struct { p1 interface{} b1 bool } // Expect sets up expected params for Cache.Get func (mmGet *mCacheMockGet) Expect(key string) *mCacheMockGet { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("CacheMock.Get mock is already set by Set") } if mmGet.defaultExpectation == nil { mmGet.defaultExpectation = &CacheMockGetExpectation{} } mmGet.defaultExpectation.params = &CacheMockGetParams{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 Cache.Get func (mmGet *mCacheMockGet) Inspect(f func(key string)) *mCacheMockGet { if mmGet.mock.inspectFuncGet != nil { mmGet.mock.t.Fatalf("Inspect function is already set for CacheMock.Get") } mmGet.mock.inspectFuncGet = f return mmGet } // Return sets up results that will be returned by Cache.Get func (mmGet *mCacheMockGet) Return(p1 interface{}, b1 bool) *CacheMock { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("CacheMock.Get mock is already set by Set") } if mmGet.defaultExpectation == nil { mmGet.defaultExpectation = &CacheMockGetExpectation{mock: mmGet.mock} } mmGet.defaultExpectation.results = &CacheMockGetResults{p1, b1} return mmGet.mock } // Set uses given function f to mock the Cache.Get method func (mmGet *mCacheMockGet) Set(f func(key string) (p1 interface{}, b1 bool)) *CacheMock { if mmGet.defaultExpectation != nil { mmGet.mock.t.Fatalf("Default expectation is already set for the Cache.Get method") } if len(mmGet.expectations) > 0 { mmGet.mock.t.Fatalf("Some expectations are already set for the Cache.Get method") } mmGet.mock.funcGet = f return mmGet.mock } // When sets expectation for the Cache.Get which will trigger the result defined by the following // Then helper func (mmGet *mCacheMockGet) When(key string) *CacheMockGetExpectation { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("CacheMock.Get mock is already set by Set") } expectation := &CacheMockGetExpectation{ mock: mmGet.mock, params: &CacheMockGetParams{key}, } mmGet.expectations = append(mmGet.expectations, expectation) return expectation } // Then sets up Cache.Get return parameters for the expectation previously defined by the When method func (e *CacheMockGetExpectation) Then(p1 interface{}, b1 bool) *CacheMock { e.results = &CacheMockGetResults{p1, b1} return e.mock } // Get implements interfaces.Cache func (mmGet *CacheMock) 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 := &CacheMockGetParams{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 := CacheMockGetParams{key} if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmGet.t.Errorf("CacheMock.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 CacheMock.Get") } return (*mm_results).p1, (*mm_results).b1 } if mmGet.funcGet != nil { return mmGet.funcGet(key) } mmGet.t.Fatalf("Unexpected call to CacheMock.Get. %v", key) return } // GetAfterCounter returns a count of finished CacheMock.Get invocations func (mmGet *CacheMock) GetAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmGet.afterGetCounter) } // GetBeforeCounter returns a count of CacheMock.Get invocations func (mmGet *CacheMock) GetBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmGet.beforeGetCounter) } // Calls returns a list of arguments used in each call to CacheMock.Get. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmGet *mCacheMockGet) Calls() []*CacheMockGetParams { mmGet.mutex.RLock() argCopy := make([]*CacheMockGetParams, 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 *CacheMock) 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 *CacheMock) MinimockGetInspect() { for _, e := range m.GetMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to CacheMock.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 CacheMock.Get") } else { m.t.Errorf("Expected call to CacheMock.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 CacheMock.Get") } } type mCacheMockSet struct { mock *CacheMock defaultExpectation *CacheMockSetExpectation expectations []*CacheMockSetExpectation callArgs []*CacheMockSetParams mutex sync.RWMutex } // CacheMockSetExpectation specifies expectation struct of the Cache.Set type CacheMockSetExpectation struct { mock *CacheMock params *CacheMockSetParams Counter uint64 } // CacheMockSetParams contains parameters of the Cache.Set type CacheMockSetParams struct { key string value interface{} } // Expect sets up expected params for Cache.Set func (mmSet *mCacheMockSet) Expect(key string, value interface{}) *mCacheMockSet { if mmSet.mock.funcSet != nil { mmSet.mock.t.Fatalf("CacheMock.Set mock is already set by Set") } if mmSet.defaultExpectation == nil { mmSet.defaultExpectation = &CacheMockSetExpectation{} } mmSet.defaultExpectation.params = &CacheMockSetParams{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 Cache.Set func (mmSet *mCacheMockSet) Inspect(f func(key string, value interface{})) *mCacheMockSet { if mmSet.mock.inspectFuncSet != nil { mmSet.mock.t.Fatalf("Inspect function is already set for CacheMock.Set") } mmSet.mock.inspectFuncSet = f return mmSet } // Return sets up results that will be returned by Cache.Set func (mmSet *mCacheMockSet) Return() *CacheMock { if mmSet.mock.funcSet != nil { mmSet.mock.t.Fatalf("CacheMock.Set mock is already set by Set") } if mmSet.defaultExpectation == nil { mmSet.defaultExpectation = &CacheMockSetExpectation{mock: mmSet.mock} } return mmSet.mock } // Set uses given function f to mock the Cache.Set method func (mmSet *mCacheMockSet) Set(f func(key string, value interface{})) *CacheMock { if mmSet.defaultExpectation != nil { mmSet.mock.t.Fatalf("Default expectation is already set for the Cache.Set method") } if len(mmSet.expectations) > 0 { mmSet.mock.t.Fatalf("Some expectations are already set for the Cache.Set method") } mmSet.mock.funcSet = f return mmSet.mock } // Set implements interfaces.Cache func (mmSet *CacheMock) 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 := &CacheMockSetParams{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 := CacheMockSetParams{key, value} if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmSet.t.Errorf("CacheMock.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 CacheMock.Set. %v %v", key, value) } // SetAfterCounter returns a count of finished CacheMock.Set invocations func (mmSet *CacheMock) SetAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmSet.afterSetCounter) } // SetBeforeCounter returns a count of CacheMock.Set invocations func (mmSet *CacheMock) SetBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmSet.beforeSetCounter) } // Calls returns a list of arguments used in each call to CacheMock.Set. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmSet *mCacheMockSet) Calls() []*CacheMockSetParams { mmSet.mutex.RLock() argCopy := make([]*CacheMockSetParams, 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 *CacheMock) 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 *CacheMock) MinimockSetInspect() { for _, e := range m.SetMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to CacheMock.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 CacheMock.Set") } else { m.t.Errorf("Expected call to CacheMock.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 CacheMock.Set") } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *CacheMock) 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 *CacheMock) 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 *CacheMock) minimockDone() bool { done := true return done && m.MinimockFlushAllDone() && m.MinimockGetDone() && m.MinimockSetDone() }