123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629 |
- package mocks
- // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT.
- //go:generate minimock -i git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/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()
- }
|