From 0966a70b43bac6f7d966982b7273117073d94bf3 Mon Sep 17 00:00:00 2001 From: purcarea Date: Wed, 12 Aug 2020 13:30:21 +0300 Subject: [PATCH] update tests --- cache/chain_test.go | 19 ++++++++---- cache/metric_test.go | 3 +- test/mocks/cache/cache_interface.go | 48 ++++++++++------------------- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/cache/chain_test.go b/cache/chain_test.go index a689cb7..f8a8648 100644 --- a/cache/chain_test.go +++ b/cache/chain_test.go @@ -71,7 +71,8 @@ func TestChainGetWhenAvailableInFirstCache(t *testing.T) { cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) cache1.EXPECT().GetCodec().AnyTimes().Return(codec1) - cache1.EXPECT().Get("my-key").Return(cacheValue, nil) + cache1.EXPECT().GetWithTTL("my-key").Return(cacheValue, + 0*time.Second, nil) // Cache 2 cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) @@ -102,6 +103,8 @@ func TestChainGetWhenAvailableInSecondCache(t *testing.T) { Hello: "world", } + options := &store.Options{Expiration: 0 * time.Second} + // Cache 1 store1 := mocksStore.NewMockStoreInterface(ctrl) store1.EXPECT().GetType().AnyTimes().Return("store1") @@ -111,8 +114,9 @@ func TestChainGetWhenAvailableInSecondCache(t *testing.T) { cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) cache1.EXPECT().GetCodec().AnyTimes().Return(codec1) - cache1.EXPECT().Get("my-key").Return(nil, errors.New("Unable to find in cache 1")) - cache1.EXPECT().Set("my-key", cacheValue, nil).AnyTimes().Return(nil) + cache1.EXPECT().GetWithTTL("my-key").Return(nil, 0*time.Second, + errors.New("Unable to find in cache 1")) + cache1.EXPECT().Set("my-key", cacheValue, options).AnyTimes().Return(nil) // Cache 2 store2 := mocksStore.NewMockStoreInterface(ctrl) @@ -123,7 +127,8 @@ func TestChainGetWhenAvailableInSecondCache(t *testing.T) { cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) cache2.EXPECT().GetCodec().AnyTimes().Return(codec2) - cache2.EXPECT().Get("my-key").Return(cacheValue, nil) + cache2.EXPECT().GetWithTTL("my-key").Return(cacheValue, + 0*time.Second, nil) cache := NewChain(cache1, cache2) @@ -154,7 +159,8 @@ func TestChainGetWhenNotAvailableInAnyCache(t *testing.T) { cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) cache1.EXPECT().GetCodec().Return(codec1) - cache1.EXPECT().Get("my-key").Return(nil, errors.New("Unable to find in cache 1")) + cache1.EXPECT().GetWithTTL("my-key").Return(nil, 0*time.Second, + errors.New("Unable to find in cache 1")) // Cache 2 store2 := mocksStore.NewMockStoreInterface(ctrl) @@ -165,7 +171,8 @@ func TestChainGetWhenNotAvailableInAnyCache(t *testing.T) { cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) cache2.EXPECT().GetCodec().Return(codec2) - cache2.EXPECT().Get("my-key").Return(nil, errors.New("Unable to find in cache 2")) + cache2.EXPECT().GetWithTTL("my-key").Return(nil, 0*time.Second, + errors.New("Unable to find in cache 2")) cache := NewChain(cache1, cache2) diff --git a/cache/metric_test.go b/cache/metric_test.go index e3569df..dd7bc65 100644 --- a/cache/metric_test.go +++ b/cache/metric_test.go @@ -81,7 +81,8 @@ func TestMetricGetWhenChainCache(t *testing.T) { codec1.EXPECT().GetStore().AnyTimes().Return(store1) cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) - cache1.EXPECT().Get("my-key").Return(cacheValue, nil) + cache1.EXPECT().GetWithTTL("my-key").Return(cacheValue, + 0*time.Second, nil) cache1.EXPECT().GetCodec().AnyTimes().Return(codec1) chainCache := NewChain(cache1) diff --git a/test/mocks/cache/cache_interface.go b/test/mocks/cache/cache_interface.go index 16a18f2..965792a 100644 --- a/test/mocks/cache/cache_interface.go +++ b/test/mocks/cache/cache_interface.go @@ -50,22 +50,6 @@ func (mr *MockCacheInterfaceMockRecorder) Get(key interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockCacheInterface)(nil).Get), key) } -// GetWithTTL mocks base method -func (m *MockCacheInterface) GetWithTTL(key interface{}) (interface{}, time.Duration, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetWithTTL", key) - ret0, _ := ret[0].(interface{}) - ret1, _ := ret[1].(time.Duration) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 -} - -// GetWithTTL indicates an expected call of GetWithTTL -func (mr *MockCacheInterfaceMockRecorder) GetWithTTL(key interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWithTTL", reflect.TypeOf((*MockCacheInterface)(nil).GetWithTTL), key) -} - // Set mocks base method func (m *MockCacheInterface) Set(key, object interface{}, options *store.Options) error { m.ctrl.T.Helper() @@ -174,22 +158,6 @@ func (mr *MockSetterCacheInterfaceMockRecorder) Get(key interface{}) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockSetterCacheInterface)(nil).Get), key) } -// GetWithTTL mocks base method -func (m *MockSetterCacheInterface) GetWithTTL(key interface{}) (interface{}, time.Duration, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetWithTTL", key) - ret0, _ := ret[0].(interface{}) - ret1, _ := ret[1].(time.Duration) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 -} - -// GetWithTTL indicates an expected call of GetWithTTL -func (mr *MockSetterCacheInterfaceMockRecorder) GetWithTTL(key interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWithTTL", reflect.TypeOf((*MockSetterCacheInterface)(nil).GetWithTTL), key) -} - // Set mocks base method func (m *MockSetterCacheInterface) Set(key, object interface{}, options *store.Options) error { m.ctrl.T.Helper() @@ -260,6 +228,22 @@ func (mr *MockSetterCacheInterfaceMockRecorder) GetType() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetType", reflect.TypeOf((*MockSetterCacheInterface)(nil).GetType)) } +// GetWithTTL mocks base method +func (m *MockSetterCacheInterface) GetWithTTL(key interface{}) (interface{}, time.Duration, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetWithTTL", key) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(time.Duration) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetWithTTL indicates an expected call of GetWithTTL +func (mr *MockSetterCacheInterfaceMockRecorder) GetWithTTL(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWithTTL", reflect.TypeOf((*MockSetterCacheInterface)(nil).GetWithTTL), key) +} + // GetCodec mocks base method func (m *MockSetterCacheInterface) GetCodec() codec.CodecInterface { m.ctrl.T.Helper()