Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
corinapurcarea committed Aug 12, 2020
1 parent 3810cba commit 0966a70
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 39 deletions.
19 changes: 13 additions & 6 deletions cache/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion cache/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 16 additions & 32 deletions test/mocks/cache/cache_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0966a70

Please sign in to comment.