diff --git a/.travis.yml b/.travis.yml index c5d0316..7773401 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ install: - go get -t -v ./... script: - - go test -cover -coverprofile=coverage.txt -covermode=atomic -v ./... + - go test -race -cover -coverprofile=coverage.txt -covermode=atomic -v ./... after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile index 41a195c..6c7758e 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,11 @@ .PHONY: mocks mocks: - # mocks - mockery -case=snake -name=CacheInterface -dir=cache/ -output test/mocks/cache/ - mockery -case=snake -name=CodecInterface -dir=codec/ -output test/mocks/codec/ - mockery -case=snake -name=SetterCacheInterface -dir=cache/ -output test/mocks/cache/ - mockery -case=snake -name=MetricsInterface -dir=metrics/ -output test/mocks/metrics/ - mockery -case=snake -name=StoreInterface -dir=store/ -output test/mocks/store/ - mockery -case=snake -name=BigcacheClientInterface -dir=store/ -output test/mocks/store/clients/ - mockery -case=snake -name=MemcacheClientInterface -dir=store/ -output test/mocks/store/clients/ - mockery -case=snake -name=RedisClientInterface -dir=store/ -output test/mocks/store/clients/ - mockery -case=snake -name=RistrettoClientInterface -dir=store/ -output test/mocks/store/clients/ + mockgen -source=cache/interface.go -destination=test/mocks/cache/cache_interface.go -package=mocks + mockgen -source=codec/interface.go -destination=test/mocks/codec/codec_interface.go -package=mocks + mockgen -source=metrics/interface.go -destination=test/mocks/metrics/metrics_interface.go -package=mocks + mockgen -source=store/interface.go -destination=test/mocks/store/store_interface.go -package=mocks + mockgen -source=store/bigcache.go -destination=test/mocks/store/clients/bigcache_interface.go -package=mocks + mockgen -source=store/memcache.go -destination=test/mocks/store/clients/memcache_interface.go -package=mocks + mockgen -source=store/redis.go -destination=test/mocks/store/clients/redis_interface.go -package=mocks + mockgen -source=store/ristretto.go -destination=test/mocks/store/clients/ristretto_interface.go -package=mocks diff --git a/cache/cache_test.go b/cache/cache_test.go index b943e58..9d422fc 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -8,13 +8,17 @@ import ( "github.com/eko/gocache/codec" "github.com/eko/gocache/store" mocksStore "github.com/eko/gocache/test/mocks/store" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) func TestNew(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) // When cache := New(store) @@ -28,6 +32,9 @@ func TestNew(t *testing.T) { func TestCacheSet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := &store.Options{ Expiration: 5 * time.Second, } @@ -38,9 +45,8 @@ func TestCacheSet(t *testing.T) { Hello: "world", } - store := &mocksStore.StoreInterface{} - store.On("Set", "9b1ac8a6e8ca8ca9477c0a252eb37756", value, options). - Return(nil) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Set("9b1ac8a6e8ca8ca9477c0a252eb37756", value, options).Return(nil) cache := New(store) @@ -51,6 +57,9 @@ func TestCacheSet(t *testing.T) { func TestCacheSetWhenErrorOccurs(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := &store.Options{ Expiration: 5 * time.Second, } @@ -63,9 +72,8 @@ func TestCacheSetWhenErrorOccurs(t *testing.T) { storeErr := errors.New("An error has occurred while inserting data into store") - store := &mocksStore.StoreInterface{} - store.On("Set", "9b1ac8a6e8ca8ca9477c0a252eb37756", value, options). - Return(storeErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Set("9b1ac8a6e8ca8ca9477c0a252eb37756", value, options).Return(storeErr) cache := New(store) @@ -76,14 +84,17 @@ func TestCacheSetWhenErrorOccurs(t *testing.T) { func TestCacheGet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ Hello: "world", } - store := &mocksStore.StoreInterface{} - store.On("Get", "9b1ac8a6e8ca8ca9477c0a252eb37756").Return(cacheValue, nil) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Get("9b1ac8a6e8ca8ca9477c0a252eb37756").Return(cacheValue, nil) cache := New(store) @@ -97,10 +108,13 @@ func TestCacheGet(t *testing.T) { func TestCacheGetWhenNotFound(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + returnedErr := errors.New("Unable to find item in store") - store := &mocksStore.StoreInterface{} - store.On("Get", "9b1ac8a6e8ca8ca9477c0a252eb37756").Return(nil, returnedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Get("9b1ac8a6e8ca8ca9477c0a252eb37756").Return(nil, returnedErr) cache := New(store) @@ -114,7 +128,10 @@ func TestCacheGetWhenNotFound(t *testing.T) { func TestCacheGetCodec(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) cache := New(store) @@ -128,7 +145,10 @@ func TestCacheGetCodec(t *testing.T) { func TestCacheGetType(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) cache := New(store) @@ -138,8 +158,11 @@ func TestCacheGetType(t *testing.T) { func TestCacheDelete(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} - store.On("Delete", "9b1ac8a6e8ca8ca9477c0a252eb37756").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Delete("9b1ac8a6e8ca8ca9477c0a252eb37756").Return(nil) cache := New(store) @@ -152,12 +175,15 @@ func TestCacheDelete(t *testing.T) { func TestCacheInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } - store := &mocksStore.StoreInterface{} - store.On("Invalidate", options).Return(nil) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Invalidate(options).Return(nil) cache := New(store) @@ -170,14 +196,17 @@ func TestCacheInvalidate(t *testing.T) { func TestCacheInvalidateWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } expectedErr := errors.New("Unexpected error during invalidation") - store := &mocksStore.StoreInterface{} - store.On("Invalidate", options).Return(expectedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Invalidate(options).Return(expectedErr) cache := New(store) @@ -190,8 +219,11 @@ func TestCacheInvalidateWhenError(t *testing.T) { func TestCacheClear(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} - store.On("Clear").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Clear().Return(nil) cache := New(store) @@ -204,10 +236,13 @@ func TestCacheClear(t *testing.T) { func TestCacheClearWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unexpected error during invalidation") - store := &mocksStore.StoreInterface{} - store.On("Clear").Return(expectedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Clear().Return(expectedErr) cache := New(store) @@ -220,10 +255,13 @@ func TestCacheClearWhenError(t *testing.T) { func TestCacheDeleteWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to delete key") - store := &mocksStore.StoreInterface{} - store.On("Delete", "9b1ac8a6e8ca8ca9477c0a252eb37756").Return(expectedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Delete("9b1ac8a6e8ca8ca9477c0a252eb37756").Return(expectedErr) cache := New(store) diff --git a/cache/chain.go b/cache/chain.go index e3d3e33..16fe6f8 100644 --- a/cache/chain.go +++ b/cache/chain.go @@ -12,15 +12,40 @@ const ( ChainType = "chain" ) +type chainKeyValue struct { + key interface{} + value interface{} + storeType *string +} + // ChainCache represents the configuration needed by a cache aggregator type ChainCache struct { - caches []SetterCacheInterface + caches []SetterCacheInterface + setChannel chan *chainKeyValue } // NewChain instanciates a new cache aggregator func NewChain(caches ...SetterCacheInterface) *ChainCache { - return &ChainCache{ - caches: caches, + chain := &ChainCache{ + caches: caches, + setChannel: make(chan *chainKeyValue, 10000), + } + + go chain.setter() + + return chain +} + +// setter sets a value in available caches, until a given cache layer +func (c *ChainCache) setter() { + for item := range c.setChannel { + for _, cache := range c.caches { + if item.storeType != nil && *item.storeType == cache.GetCodec().GetStore().GetType() { + break + } + + cache.Set(item.key, item.value, nil) + } } } @@ -34,7 +59,7 @@ func (c *ChainCache) Get(key interface{}) (interface{}, error) { object, err = cache.Get(key) if err == nil { // Set the value back until this cache layer - go c.setUntil(key, object, &storeType) + c.setChannel <- &chainKeyValue{key, object, &storeType} return object, nil } @@ -84,17 +109,6 @@ func (c *ChainCache) Clear() error { return nil } -// setUntil sets a value in available caches, eventually until a given cache layer -func (c *ChainCache) setUntil(key, object interface{}, until *string) { - for _, cache := range c.caches { - if until != nil && *until == cache.GetCodec().GetStore().GetType() { - break - } - - cache.Set(key, object, nil) - } -} - // GetCaches returns all Chaind caches func (c *ChainCache) GetCaches() []SetterCacheInterface { return c.caches diff --git a/cache/chain_test.go b/cache/chain_test.go index 7bbf98f..a689cb7 100644 --- a/cache/chain_test.go +++ b/cache/chain_test.go @@ -4,18 +4,23 @@ import ( "errors" "fmt" "testing" + "time" "github.com/eko/gocache/store" mocksCache "github.com/eko/gocache/test/mocks/cache" mocksCodec "github.com/eko/gocache/test/mocks/codec" mocksStore "github.com/eko/gocache/test/mocks/store" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) func TestNewChain(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} - cache2 := &mocksCache.SetterCacheInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) // When cache := NewChain(cache1, cache2) @@ -28,8 +33,11 @@ func TestNewChain(t *testing.T) { func TestChainGetCaches(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} - cache2 := &mocksCache.SetterCacheInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) cache := NewChain(cache1, cache2) @@ -45,6 +53,9 @@ func TestChainGetCaches(t *testing.T) { func TestChainGetWhenAvailableInFirstCache(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ @@ -52,26 +63,29 @@ func TestChainGetWhenAvailableInFirstCache(t *testing.T) { } // Cache 1 - store1 := &mocksStore.StoreInterface{} - store1.On("GetType").Return("store1") + store1 := mocksStore.NewMockStoreInterface(ctrl) + store1.EXPECT().GetType().AnyTimes().Return("store1") - codec1 := &mocksCodec.CodecInterface{} - codec1.On("GetStore").Return(store1) + codec1 := mocksCodec.NewMockCodecInterface(ctrl) + codec1.EXPECT().GetStore().AnyTimes().Return(store1) - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("GetCodec").Return(codec1) - cache1.On("Get", "my-key").Return(cacheValue, nil) - cache1.AssertNotCalled(t, "Set") + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().GetCodec().AnyTimes().Return(codec1) + cache1.EXPECT().Get("my-key").Return(cacheValue, nil) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.AssertNotCalled(t, "Get") + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) cache := NewChain(cache1, cache2) // When value, err := cache.Get("my-key") + // Wait for data to be processed + for len(cache.setChannel) > 0 { + time.Sleep(1 * time.Millisecond) + } + // Then assert.Nil(t, err) assert.Equal(t, cacheValue, value) @@ -79,6 +93,9 @@ func TestChainGetWhenAvailableInFirstCache(t *testing.T) { func TestChainGetWhenAvailableInSecondCache(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ @@ -86,34 +103,38 @@ func TestChainGetWhenAvailableInSecondCache(t *testing.T) { } // Cache 1 - store1 := &mocksStore.StoreInterface{} - store1.On("GetType").Return("store1") + store1 := mocksStore.NewMockStoreInterface(ctrl) + store1.EXPECT().GetType().AnyTimes().Return("store1") - codec1 := &mocksCodec.CodecInterface{} - codec1.On("GetStore").Return(store1) + codec1 := mocksCodec.NewMockCodecInterface(ctrl) + codec1.EXPECT().GetStore().AnyTimes().Return(store1) - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("GetCodec").Return(codec1) - cache1.On("Get", "my-key").Return(nil, errors.New("Unable to find in cache 1")) - cache1.On("Set", "my-key", cacheValue, (*store.Options)(nil)).Return(nil) + 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) // Cache 2 - store2 := &mocksStore.StoreInterface{} - store2.On("GetType").Return("store2") + store2 := mocksStore.NewMockStoreInterface(ctrl) + store2.EXPECT().GetType().AnyTimes().Return("store2") - codec2 := &mocksCodec.CodecInterface{} - codec2.On("GetStore").Return(store2) + codec2 := mocksCodec.NewMockCodecInterface(ctrl) + codec2.EXPECT().GetStore().AnyTimes().Return(store2) - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("GetCodec").Return(codec2) - cache2.On("Get", "my-key").Return(cacheValue, nil) - cache2.AssertNotCalled(t, "Set") + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().GetCodec().AnyTimes().Return(codec2) + cache2.EXPECT().Get("my-key").Return(cacheValue, nil) cache := NewChain(cache1, cache2) // When value, err := cache.Get("my-key") + // Wait for data to be processed + for len(cache.setChannel) > 0 { + time.Sleep(1 * time.Millisecond) + } + // Then assert.Nil(t, err) assert.Equal(t, cacheValue, value) @@ -121,28 +142,30 @@ func TestChainGetWhenAvailableInSecondCache(t *testing.T) { func TestChainGetWhenNotAvailableInAnyCache(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + // Cache 1 - store1 := &mocksStore.StoreInterface{} - store1.On("GetType").Return("store1") + store1 := mocksStore.NewMockStoreInterface(ctrl) + store1.EXPECT().GetType().Return("store1") - codec1 := &mocksCodec.CodecInterface{} - codec1.On("GetStore").Return(store1) + codec1 := mocksCodec.NewMockCodecInterface(ctrl) + codec1.EXPECT().GetStore().Return(store1) - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("GetCodec").Return(codec1) - cache1.On("Get", "my-key").Return(nil, errors.New("Unable to find in cache 1")) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().GetCodec().Return(codec1) + cache1.EXPECT().Get("my-key").Return(nil, errors.New("Unable to find in cache 1")) // Cache 2 - store2 := &mocksStore.StoreInterface{} - store2.On("GetType").Return("store2") + store2 := mocksStore.NewMockStoreInterface(ctrl) + store2.EXPECT().GetType().Return("store2") - codec2 := &mocksCodec.CodecInterface{} - codec2.On("GetStore").Return(store2) + codec2 := mocksCodec.NewMockCodecInterface(ctrl) + codec2.EXPECT().GetStore().Return(store2) - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("GetCodec").Return(codec2) - cache2.On("Get", "my-key").Return(nil, errors.New("Unable to find in cache 2")) - cache2.AssertNotCalled(t, "Set") + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().GetCodec().Return(codec2) + cache2.EXPECT().Get("my-key").Return(nil, errors.New("Unable to find in cache 2")) cache := NewChain(cache1, cache2) @@ -156,6 +179,9 @@ func TestChainGetWhenNotAvailableInAnyCache(t *testing.T) { func TestChainSet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ @@ -165,12 +191,12 @@ func TestChainSet(t *testing.T) { options := &store.Options{} // Cache 1 - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Set", "my-key", cacheValue, options).Return(nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Set("my-key", cacheValue, options).Return(nil) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("Set", "my-key", cacheValue, options).Return(nil) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().Set("my-key", cacheValue, options).Return(nil) cache := NewChain(cache1, cache2) @@ -183,6 +209,9 @@ func TestChainSet(t *testing.T) { func TestChainSetWhenErrorOnSetting(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ @@ -194,19 +223,18 @@ func TestChainSetWhenErrorOnSetting(t *testing.T) { expectedErr := errors.New("An unexpected error occurred while setting data") // Cache 1 - store1 := &mocksStore.StoreInterface{} - store1.On("GetType").Return("store1") + store1 := mocksStore.NewMockStoreInterface(ctrl) + store1.EXPECT().GetType().Return("store1") - codec1 := &mocksCodec.CodecInterface{} - codec1.On("GetStore").Return(store1) + codec1 := mocksCodec.NewMockCodecInterface(ctrl) + codec1.EXPECT().GetStore().Return(store1) - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("GetCodec").Return(codec1) - cache1.On("Set", "my-key", cacheValue, options).Return(expectedErr) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().GetCodec().Return(codec1) + cache1.EXPECT().Set("my-key", cacheValue, options).Return(expectedErr) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.AssertNotCalled(t, "Set") + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) cache := NewChain(cache1, cache2) @@ -220,13 +248,16 @@ func TestChainSetWhenErrorOnSetting(t *testing.T) { func TestChainDelete(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + // Cache 1 - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Delete", "my-key").Return(nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Delete("my-key").Return(nil) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("Delete", "my-key").Return(nil) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().Delete("my-key").Return(nil) cache := NewChain(cache1, cache2) @@ -239,13 +270,16 @@ func TestChainDelete(t *testing.T) { func TestChainDeleteWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + // Cache 1 - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Delete", "my-key").Return(errors.New("An error has occurred while deleting key")) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Delete("my-key").Return(errors.New("An error has occurred while deleting key")) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("Delete", "my-key").Return(nil) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().Delete("my-key").Return(nil) cache := NewChain(cache1, cache2) @@ -258,17 +292,20 @@ func TestChainDeleteWhenError(t *testing.T) { func TestChainInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } // Cache 1 - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Invalidate", options).Return(nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Invalidate(options).Return(nil) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("Invalidate", options).Return(nil) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().Invalidate(options).Return(nil) cache := NewChain(cache1, cache2) @@ -281,17 +318,20 @@ func TestChainInvalidate(t *testing.T) { func TestChainInvalidateWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } // Cache 1 - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Invalidate", options).Return(errors.New("An unexpected error has occurred while invalidation data")) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Invalidate(options).Return(errors.New("An unexpected error has occurred while invalidation data")) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("Invalidate", options).Return(nil) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().Invalidate(options).Return(nil) cache := NewChain(cache1, cache2) @@ -304,13 +344,16 @@ func TestChainInvalidateWhenError(t *testing.T) { func TestChainClear(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + // Cache 1 - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Clear").Return(nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Clear().Return(nil) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("Clear").Return(nil) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().Clear().Return(nil) cache := NewChain(cache1, cache2) @@ -323,13 +366,16 @@ func TestChainClear(t *testing.T) { func TestChainClearWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + // Cache 1 - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Clear").Return(errors.New("An unexpected error has occurred while invalidation data")) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Clear().Return(errors.New("An unexpected error has occurred while invalidation data")) // Cache 2 - cache2 := &mocksCache.SetterCacheInterface{} - cache2.On("Clear").Return(nil) + cache2 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache2.EXPECT().Clear().Return(nil) cache := NewChain(cache1, cache2) @@ -342,7 +388,10 @@ func TestChainClearWhenError(t *testing.T) { func TestChainGetType(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) cache := NewChain(cache1) diff --git a/cache/loadable.go b/cache/loadable.go index f8dfc93..0ddc458 100644 --- a/cache/loadable.go +++ b/cache/loadable.go @@ -11,19 +11,36 @@ const ( LoadableType = "loadable" ) +type loadableKeyValue struct { + key interface{} + value interface{} +} + type loadFunction func(key interface{}) (interface{}, error) // LoadableCache represents a cache that uses a function to load data type LoadableCache struct { - loadFunc loadFunction - cache CacheInterface + loadFunc loadFunction + cache CacheInterface + setChannel chan *loadableKeyValue } // NewLoadable instanciates a new cache that uses a function to load data func NewLoadable(loadFunc loadFunction, cache CacheInterface) *LoadableCache { - return &LoadableCache{ - loadFunc: loadFunc, - cache: cache, + loadable := &LoadableCache{ + loadFunc: loadFunc, + cache: cache, + setChannel: make(chan *loadableKeyValue, 10000), + } + + go loadable.setter() + + return loadable +} + +func (c *LoadableCache) setter() { + for item := range c.setChannel { + c.Set(item.key, item.value, nil) } } @@ -44,7 +61,7 @@ func (c *LoadableCache) Get(key interface{}) (interface{}, error) { } // Then, put it back in cache - go c.Set(key, object, nil) + c.setChannel <- &loadableKeyValue{key, object} return object, err } diff --git a/cache/loadable_test.go b/cache/loadable_test.go index a9e4c5e..64cdb35 100644 --- a/cache/loadable_test.go +++ b/cache/loadable_test.go @@ -3,17 +3,20 @@ package cache import ( "errors" "testing" + "time" "github.com/eko/gocache/store" mocksCache "github.com/eko/gocache/test/mocks/cache" - mocksCodec "github.com/eko/gocache/test/mocks/codec" - mocksStore "github.com/eko/gocache/test/mocks/store" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) func TestNewLoadable(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) loadFunc := func(key interface{}) (interface{}, error) { return "test data loaded", nil @@ -31,14 +34,17 @@ func TestNewLoadable(t *testing.T) { func TestLoadableGetWhenAlreadyInCache(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ Hello: "world", } - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Get", "my-key").Return(cacheValue, nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Get("my-key").Return(cacheValue, nil) loadFunc := func(key interface{}) (interface{}, error) { return nil, errors.New("Should not be called") @@ -56,16 +62,12 @@ func TestLoadableGetWhenAlreadyInCache(t *testing.T) { func TestLoadableGetWhenNotAvailableInLoadFunc(t *testing.T) { // Given - // Cache - store1 := &mocksStore.StoreInterface{} - store1.On("GetType").Return("store1") + ctrl := gomock.NewController(t) + defer ctrl.Finish() - codec1 := &mocksCodec.CodecInterface{} - codec1.On("GetStore").Return(store1) - - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("GetCodec").Return(codec1) - cache1.On("Get", "my-key").Return(nil, errors.New("Unable to find in cache 1")) + // Cache + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Get("my-key").Return(nil, errors.New("Unable to find in cache 1")) loadFunc := func(key interface{}) (interface{}, error) { return nil, errors.New("An error has occurred while loading data from custom source") @@ -83,6 +85,9 @@ func TestLoadableGetWhenNotAvailableInLoadFunc(t *testing.T) { func TestLoadableGetWhenAvailableInLoadFunc(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ @@ -90,16 +95,9 @@ func TestLoadableGetWhenAvailableInLoadFunc(t *testing.T) { } // Cache 1 - store1 := &mocksStore.StoreInterface{} - store1.On("GetType").Return("store1") - - codec1 := &mocksCodec.CodecInterface{} - codec1.On("GetStore").Return(store1) - - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("GetCodec").Return(codec1) - cache1.On("Get", "my-key").Return(nil, errors.New("Unable to find in cache 1")) - cache1.On("Set", "my-key", cacheValue, (*store.Options)(nil)).Return(nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Get("my-key").Return(nil, errors.New("Unable to find in cache 1")) + cache1.EXPECT().Set("my-key", cacheValue, (*store.Options)(nil)).AnyTimes().Return(nil) loadFunc := func(key interface{}) (interface{}, error) { return cacheValue, nil @@ -110,6 +108,11 @@ func TestLoadableGetWhenAvailableInLoadFunc(t *testing.T) { // When value, err := cache.Get("my-key") + // Wait for data to be processed + for len(cache.setChannel) > 0 { + time.Sleep(1 * time.Millisecond) + } + // Then assert.Nil(t, err) assert.Equal(t, cacheValue, value) @@ -117,8 +120,11 @@ func TestLoadableGetWhenAvailableInLoadFunc(t *testing.T) { func TestLoadableDelete(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Delete", "my-key").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Delete("my-key").Return(nil) loadFunc := func(key interface{}) (interface{}, error) { return "a value", nil @@ -135,10 +141,13 @@ func TestLoadableDelete(t *testing.T) { func TestLoadableDeleteWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to delete key") - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Delete", "my-key").Return(expectedErr) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Delete("my-key").Return(expectedErr) loadFunc := func(key interface{}) (interface{}, error) { return "a value", nil @@ -155,12 +164,15 @@ func TestLoadableDeleteWhenError(t *testing.T) { func TestLoadableInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Invalidate", options).Return(nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Invalidate(options).Return(nil) loadFunc := func(key interface{}) (interface{}, error) { return "a value", nil @@ -177,14 +189,17 @@ func TestLoadableInvalidate(t *testing.T) { func TestLoadableInvalidateWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } expectedErr := errors.New("Unexpected error when invalidating data") - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Invalidate", options).Return(expectedErr) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Invalidate(options).Return(expectedErr) loadFunc := func(key interface{}) (interface{}, error) { return "a value", nil @@ -201,8 +216,11 @@ func TestLoadableInvalidateWhenError(t *testing.T) { func TestLoadableClear(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Clear").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Clear().Return(nil) loadFunc := func(key interface{}) (interface{}, error) { return "a value", nil @@ -219,10 +237,13 @@ func TestLoadableClear(t *testing.T) { func TestLoadableClearWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unexpected error when invalidating data") - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Clear").Return(expectedErr) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Clear().Return(expectedErr) loadFunc := func(key interface{}) (interface{}, error) { return "a value", nil @@ -239,7 +260,10 @@ func TestLoadableClearWhenError(t *testing.T) { func TestLoadableGetType(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) loadFunc := func(key interface{}) (interface{}, error) { return "test data loaded", nil diff --git a/cache/metric.go b/cache/metric.go index 0c46348..077537a 100644 --- a/cache/metric.go +++ b/cache/metric.go @@ -62,7 +62,7 @@ func (c *MetricCache) updateMetrics(cache CacheInterface) { } case SetterCacheInterface: - go c.metrics.RecordFromCodec(current.GetCodec()) + c.metrics.RecordFromCodec(current.GetCodec()) } } diff --git a/cache/metric_test.go b/cache/metric_test.go index 42344b3..e3569df 100644 --- a/cache/metric_test.go +++ b/cache/metric_test.go @@ -10,13 +10,19 @@ import ( mocksCodec "github.com/eko/gocache/test/mocks/codec" mocksMetrics "github.com/eko/gocache/test/mocks/metrics" mocksStore "github.com/eko/gocache/test/mocks/store" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) func TestNewMetric(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} - metrics := &mocksMetrics.MetricsInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // cmsClient := cmsMocks.NewMockContentClient(ctrl) + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) // When cache := NewMetric(metrics, cache1) @@ -30,19 +36,22 @@ func TestNewMetric(t *testing.T) { func TestMetricGet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ Hello: "world", } - codec1 := &mocksCodec.CodecInterface{} - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Get", "my-key").Return(cacheValue, nil) - cache1.On("GetCodec").Return(codec1) + codec1 := mocksCodec.NewMockCodecInterface(ctrl) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Get("my-key").Return(cacheValue, nil) + cache1.EXPECT().GetCodec().Return(codec1) - metrics := &mocksMetrics.MetricsInterface{} - metrics.On("RecordFromCodec", codec1) + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) + metrics.EXPECT().RecordFromCodec(codec1).AnyTimes() cache := NewMetric(metrics, cache1) @@ -56,26 +65,29 @@ func TestMetricGet(t *testing.T) { func TestMetricGetWhenChainCache(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ Hello: "world", } - store1 := &mocksStore.StoreInterface{} - store1.On("GetType").Return("store1") + store1 := mocksStore.NewMockStoreInterface(ctrl) + store1.EXPECT().GetType().AnyTimes().Return("store1") - codec1 := &mocksCodec.CodecInterface{} - codec1.On("GetStore").Return(store1) + codec1 := mocksCodec.NewMockCodecInterface(ctrl) + codec1.EXPECT().GetStore().AnyTimes().Return(store1) - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Get", "my-key").Return(cacheValue, nil) - cache1.On("GetCodec").Return(codec1) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Get("my-key").Return(cacheValue, nil) + cache1.EXPECT().GetCodec().AnyTimes().Return(codec1) chainCache := NewChain(cache1) - metrics := &mocksMetrics.MetricsInterface{} - metrics.On("RecordFromCodec", codec1) + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) + metrics.EXPECT().RecordFromCodec(codec1).AnyTimes() cache := NewMetric(metrics, chainCache) @@ -89,6 +101,9 @@ func TestMetricGetWhenChainCache(t *testing.T) { func TestMetricSet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + value := &struct { Hello string }{ @@ -99,10 +114,10 @@ func TestMetricSet(t *testing.T) { Expiration: 5 * time.Second, } - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Set", "my-key", value, options).Return(nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Set("my-key", value, options).Return(nil) - metrics := &mocksMetrics.MetricsInterface{} + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) cache := NewMetric(metrics, cache1) @@ -115,10 +130,13 @@ func TestMetricSet(t *testing.T) { func TestMetricDelete(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Delete", "my-key").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Delete("my-key").Return(nil) - metrics := &mocksMetrics.MetricsInterface{} + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) cache := NewMetric(metrics, cache1) @@ -131,12 +149,15 @@ func TestMetricDelete(t *testing.T) { func TestMetricDeleteWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to delete key") - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Delete", "my-key").Return(expectedErr) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Delete("my-key").Return(expectedErr) - metrics := &mocksMetrics.MetricsInterface{} + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) cache := NewMetric(metrics, cache1) @@ -149,14 +170,17 @@ func TestMetricDeleteWhenError(t *testing.T) { func TestMetricInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Invalidate", options).Return(nil) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Invalidate(options).Return(nil) - metrics := &mocksMetrics.MetricsInterface{} + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) cache := NewMetric(metrics, cache1) @@ -169,16 +193,19 @@ func TestMetricInvalidate(t *testing.T) { func TestMetricInvalidateWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } expectedErr := errors.New("Unexpected error while invalidating data") - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Invalidate", options).Return(expectedErr) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Invalidate(options).Return(expectedErr) - metrics := &mocksMetrics.MetricsInterface{} + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) cache := NewMetric(metrics, cache1) @@ -191,10 +218,13 @@ func TestMetricInvalidateWhenError(t *testing.T) { func TestMetricClear(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Clear").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() - metrics := &mocksMetrics.MetricsInterface{} + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Clear().Return(nil) + + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) cache := NewMetric(metrics, cache1) @@ -207,12 +237,15 @@ func TestMetricClear(t *testing.T) { func TestMetricClearWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unexpected error while clearing cache") - cache1 := &mocksCache.SetterCacheInterface{} - cache1.On("Clear").Return(expectedErr) + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + cache1.EXPECT().Clear().Return(expectedErr) - metrics := &mocksMetrics.MetricsInterface{} + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) cache := NewMetric(metrics, cache1) @@ -225,8 +258,11 @@ func TestMetricClearWhenError(t *testing.T) { func TestMetricGetType(t *testing.T) { // Given - cache1 := &mocksCache.SetterCacheInterface{} - metrics := &mocksMetrics.MetricsInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache1 := mocksCache.NewMockSetterCacheInterface(ctrl) + metrics := mocksMetrics.NewMockMetricsInterface(ctrl) cache := NewMetric(metrics, cache1) diff --git a/codec/codec_test.go b/codec/codec_test.go index 13a0c99..b2ba65b 100644 --- a/codec/codec_test.go +++ b/codec/codec_test.go @@ -7,12 +7,16 @@ import ( "github.com/eko/gocache/store" mocksStore "github.com/eko/gocache/test/mocks/store" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) func TestNew(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) // When codec := New(store) @@ -23,14 +27,17 @@ func TestNew(t *testing.T) { func TestGetWhenHit(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ Hello: "world", } - store := &mocksStore.StoreInterface{} - store.On("Get", "my-key").Return(cacheValue, nil) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Get("my-key").Return(cacheValue, nil) codec := New(store) @@ -55,10 +62,13 @@ func TestGetWhenHit(t *testing.T) { func TestGetWhenMiss(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to find in store") - store := &mocksStore.StoreInterface{} - store.On("Get", "my-key").Return(nil, expectedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Get("my-key").Return(nil, expectedErr) codec := New(store) @@ -83,6 +93,9 @@ func TestGetWhenMiss(t *testing.T) { func TestSetWhenSuccess(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ @@ -93,8 +106,8 @@ func TestSetWhenSuccess(t *testing.T) { Expiration: 5 * time.Second, } - store := &mocksStore.StoreInterface{} - store.On("Set", "my-key", cacheValue, options).Return(nil) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Set("my-key", cacheValue, options).Return(nil) codec := New(store) @@ -118,6 +131,9 @@ func TestSetWhenSuccess(t *testing.T) { func TestSetWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &struct { Hello string }{ @@ -130,8 +146,8 @@ func TestSetWhenError(t *testing.T) { expectedErr := errors.New("Unable to set value in store") - store := &mocksStore.StoreInterface{} - store.On("Set", "my-key", cacheValue, options).Return(expectedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Set("my-key", cacheValue, options).Return(expectedErr) codec := New(store) @@ -155,8 +171,11 @@ func TestSetWhenError(t *testing.T) { func TestDeleteWhenSuccess(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} - store.On("Delete", "my-key").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Delete("my-key").Return(nil) codec := New(store) @@ -180,10 +199,13 @@ func TestDeleteWhenSuccess(t *testing.T) { func TesDeleteWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to delete key") - store := &mocksStore.StoreInterface{} - store.On("Delete", "my-key").Return(expectedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Delete("my-key").Return(expectedErr) codec := New(store) @@ -207,12 +229,15 @@ func TesDeleteWhenError(t *testing.T) { func TestInvalidateWhenSuccess(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } - store := &mocksStore.StoreInterface{} - store.On("Invalidate", options).Return(nil) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Invalidate(options).Return(nil) codec := New(store) @@ -236,14 +261,17 @@ func TestInvalidateWhenSuccess(t *testing.T) { func TestInvalidateWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } expectedErr := errors.New("Unexpected error when invalidating data") - store := &mocksStore.StoreInterface{} - store.On("Invalidate", options).Return(expectedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Invalidate(options).Return(expectedErr) codec := New(store) @@ -267,8 +295,11 @@ func TestInvalidateWhenError(t *testing.T) { func TestClearWhenSuccess(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} - store.On("Clear").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Clear().Return(nil) codec := New(store) @@ -292,10 +323,13 @@ func TestClearWhenSuccess(t *testing.T) { func TestClearWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unexpected error when clearing cache") - store := &mocksStore.StoreInterface{} - store.On("Clear").Return(expectedErr) + store := mocksStore.NewMockStoreInterface(ctrl) + store.EXPECT().Clear().Return(expectedErr) codec := New(store) @@ -319,7 +353,10 @@ func TestClearWhenError(t *testing.T) { func TestGetStore(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) codec := New(store) @@ -329,7 +366,10 @@ func TestGetStore(t *testing.T) { func TestGetStats(t *testing.T) { // Given - store := &mocksStore.StoreInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + store := mocksStore.NewMockStoreInterface(ctrl) codec := New(store) diff --git a/go.mod b/go.mod index 6b53451..23edc49 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,11 @@ go 1.13 require ( github.com/allegro/bigcache v1.2.1 github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b - github.com/coreos/etcd v3.3.18+incompatible github.com/dgraph-io/ristretto v0.0.0-20191010170704-2ba187ef9534 github.com/go-redis/redis/v7 v7.0.0-beta.4 - github.com/jonboulle/clockwork v0.1.0 // indirect + github.com/golang/mock v1.3.1 github.com/kr/pretty v0.1.0 // indirect github.com/prometheus/client_golang v1.2.1 - github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 github.com/stretchr/testify v1.4.0 github.com/vmihailenco/msgpack v4.0.4+incompatible golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect diff --git a/go.sum b/go.sum index 501add7..2a023aa 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,3 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -9,45 +6,23 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= -github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0= github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.0 h1:yTUvW7Vhb89inJ+8irsUqiWjh8iT6sQPZiQzI6ReGkA= github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= -github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/etcd v3.3.17+incompatible h1:f/Z3EoDSx1yjaIjLQGo1diYUlQYSBrrAQ5vP8NjwXwo= -github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= -github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= -github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/ristretto v0.0.0-20191010170704-2ba187ef9534 h1:9G6fVccQriMJu4nXwpwLDoy9y31t/KUSLAbPcoBgv+4= github.com/dgraph-io/ristretto v0.0.0-20191010170704-2ba187ef9534/go.mod h1:edzKIzGvqUCMzhTVWbiTSe75zD9Xxq0GtSBtFmaUTZs= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -57,45 +32,21 @@ github.com/go-redis/redis/v7 v7.0.0-beta.4/go.mod h1:xhhSbUMTsleRPur+Vgx9sUHtyN3 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 h1:uHTyIjqVhYRhLbJ8nIiOJHkEZZ+5YoOsAbD3sk82NiE= -github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= -github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= -github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.12.1 h1:zCy2xE9ablevUOrUZc3Dl72Dt+ya2FNAvC2yLYMHzi4= -github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -104,11 +55,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -121,16 +69,12 @@ github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= -github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI= github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= @@ -139,33 +83,15 @@ github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1: github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= -github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= -github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= -github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -173,108 +99,48 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= -go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= -go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= -go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191002035440-2ec189313ef0 h1:2mqDk8w/o6UmeUCu5Qiq2y7iMf6anbx+YA8d1JFoFrs= -golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c h1:+EXw7AwNOKzPFXMZ1yNjO40aWCh3PIquJB2fYlv9wcs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdOCQUEXhbk/P4A9WmJq0= -golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b h1:mSUCVIwDx4hfXJfWsOPfdzEHxzb2Xjl6BQ8YgPnazQA= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191115221424-83cc0476cb11 h1:51D++eCgOHufw5VfDE9Uzqyyc+OyQIjb9hkYy9LN5Fk= -google.golang.org/genproto v0.0.0-20191115221424-83cc0476cb11/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= -google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= @@ -282,11 +148,3 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= -sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/marshaler/marshaler_test.go b/marshaler/marshaler_test.go index d9827e2..1f8896f 100644 --- a/marshaler/marshaler_test.go +++ b/marshaler/marshaler_test.go @@ -7,6 +7,7 @@ import ( "github.com/eko/gocache/store" mocksCache "github.com/eko/gocache/test/mocks/cache" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/vmihailenco/msgpack" ) @@ -17,7 +18,10 @@ type testCacheValue struct { func TestNew(t *testing.T) { // Given - cache := &mocksCache.CacheInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache := mocksCache.NewMockCacheInterface(ctrl) // When marshaler := New(cache) @@ -29,6 +33,9 @@ func TestNew(t *testing.T) { func TestGetWhenStoreReturnsSliceOfBytes(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &testCacheValue{ Hello: "world", } @@ -38,8 +45,8 @@ func TestGetWhenStoreReturnsSliceOfBytes(t *testing.T) { assert.Error(t, err) } - cache := &mocksCache.CacheInterface{} - cache.On("Get", "my-key").Return(cacheValueBytes, nil) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Get("my-key").Return(cacheValueBytes, nil) marshaler := New(cache) @@ -53,6 +60,9 @@ func TestGetWhenStoreReturnsSliceOfBytes(t *testing.T) { func TestGetWhenStoreReturnsString(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &testCacheValue{ Hello: "world", } @@ -62,8 +72,8 @@ func TestGetWhenStoreReturnsString(t *testing.T) { assert.Error(t, err) } - cache := &mocksCache.CacheInterface{} - cache.On("Get", "my-key").Return(string(cacheValueBytes), nil) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Get("my-key").Return(string(cacheValueBytes), nil) marshaler := New(cache) @@ -77,8 +87,11 @@ func TestGetWhenStoreReturnsString(t *testing.T) { func TestGetWhenUnmarshalingError(t *testing.T) { // Given - cache := &mocksCache.CacheInterface{} - cache.On("Get", "my-key").Return("unknown-string", nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Get("my-key").Return("unknown-string", nil) marshaler := New(cache) @@ -92,10 +105,13 @@ func TestGetWhenUnmarshalingError(t *testing.T) { func TestGetWhenNotFoundInStore(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to find item in store") - cache := &mocksCache.CacheInterface{} - cache.On("Get", "my-key").Return(nil, expectedErr) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Get("my-key").Return(nil, expectedErr) marshaler := New(cache) @@ -109,6 +125,9 @@ func TestGetWhenNotFoundInStore(t *testing.T) { func TestSetWhenStruct(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := &testCacheValue{ Hello: "world", } @@ -117,8 +136,8 @@ func TestSetWhenStruct(t *testing.T) { Expiration: 5 * time.Second, } - cache := &mocksCache.CacheInterface{} - cache.On("Set", "my-key", []byte{0x81, 0xa5, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xa5, 0x77, 0x6f, 0x72, 0x6c, 0x64}, options).Return(nil) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Set("my-key", []byte{0x81, 0xa5, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xa5, 0x77, 0x6f, 0x72, 0x6c, 0x64}, options).Return(nil) marshaler := New(cache) @@ -131,14 +150,17 @@ func TestSetWhenStruct(t *testing.T) { func TestSetWhenString(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := "test" options := &store.Options{ Expiration: 5 * time.Second, } - cache := &mocksCache.CacheInterface{} - cache.On("Set", "my-key", []byte{0xa4, 0x74, 0x65, 0x73, 0x74}, options).Return(nil) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Set("my-key", []byte{0xa4, 0x74, 0x65, 0x73, 0x74}, options).Return(nil) marshaler := New(cache) @@ -151,6 +173,9 @@ func TestSetWhenString(t *testing.T) { func TestSetWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheValue := "test" options := &store.Options{ @@ -159,8 +184,8 @@ func TestSetWhenError(t *testing.T) { expectedErr := errors.New("An unexpected error occurred") - cache := &mocksCache.CacheInterface{} - cache.On("Set", "my-key", []byte{0xa4, 0x74, 0x65, 0x73, 0x74}, options).Return(expectedErr) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Set("my-key", []byte{0xa4, 0x74, 0x65, 0x73, 0x74}, options).Return(expectedErr) marshaler := New(cache) @@ -173,8 +198,11 @@ func TestSetWhenError(t *testing.T) { func TestDelete(t *testing.T) { // Given - cache := &mocksCache.CacheInterface{} - cache.On("Delete", "my-key").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Delete("my-key").Return(nil) marshaler := New(cache) @@ -187,10 +215,13 @@ func TestDelete(t *testing.T) { func TestDeleteWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to delete key") - cache := &mocksCache.CacheInterface{} - cache.On("Delete", "my-key").Return(expectedErr) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Delete("my-key").Return(expectedErr) marshaler := New(cache) @@ -203,12 +234,15 @@ func TestDeleteWhenError(t *testing.T) { func TestInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } - cache := &mocksCache.CacheInterface{} - cache.On("Invalidate", options).Return(nil) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Invalidate(options).Return(nil) marshaler := New(cache) @@ -221,14 +255,17 @@ func TestInvalidate(t *testing.T) { func TestInvalidatingWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := store.InvalidateOptions{ Tags: []string{"tag1"}, } expectedErr := errors.New("Unexpected error when invalidating data") - cache := &mocksCache.CacheInterface{} - cache.On("Invalidate", options).Return(expectedErr) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Invalidate(options).Return(expectedErr) marshaler := New(cache) @@ -241,8 +278,11 @@ func TestInvalidatingWhenError(t *testing.T) { func TestClear(t *testing.T) { // Given - cache := &mocksCache.CacheInterface{} - cache.On("Clear").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Clear().Return(nil) marshaler := New(cache) @@ -255,10 +295,13 @@ func TestClear(t *testing.T) { func TestClearWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("An unexpected error occurred") - cache := &mocksCache.CacheInterface{} - cache.On("Clear").Return(expectedErr) + cache := mocksCache.NewMockCacheInterface(ctrl) + cache.EXPECT().Clear().Return(expectedErr) marshaler := New(cache) diff --git a/metrics/interface.go b/metrics/interface.go index 28f1fef..38ab75d 100644 --- a/metrics/interface.go +++ b/metrics/interface.go @@ -4,6 +4,5 @@ import "github.com/eko/gocache/codec" // MetricsInterface represents the metrics interface for all available providers type MetricsInterface interface { - Record(store, metric string, value float64) RecordFromCodec(codec codec.CodecInterface) } diff --git a/metrics/prometheus.go b/metrics/prometheus.go index e58227d..b62aa19 100644 --- a/metrics/prometheus.go +++ b/metrics/prometheus.go @@ -16,8 +16,9 @@ var ( // Prometheus represents the prometheus struct for collecting metrics type Prometheus struct { - name string - collector *prometheus.GaugeVec + service string + collector *prometheus.GaugeVec + codecChannel chan codec.CodecInterface } func initCacheCollector(namespace string) *prometheus.GaugeVec { @@ -34,28 +35,43 @@ func initCacheCollector(namespace string) *prometheus.GaugeVec { // NewPrometheus initializes a new prometheus metric instance func NewPrometheus(service string) *Prometheus { - return &Prometheus{service, cacheCollector} + prometheus := &Prometheus{ + service: service, + collector: cacheCollector, + codecChannel: make(chan codec.CodecInterface, 10000), + } + + go prometheus.recorder() + + return prometheus } // Record records a metric in prometheus by specyfing the store name, metric name and value -func (m *Prometheus) Record(store, metric string, value float64) { - m.collector.WithLabelValues(m.name, store, metric).Set(value) +func (m *Prometheus) record(store, metric string, value float64) { + m.collector.WithLabelValues(m.service, store, metric).Set(value) } -// RecordFromCodec records metrics in prometheus by retrieving values from a codec instance -func (m *Prometheus) RecordFromCodec(codec codec.CodecInterface) { - stats := codec.GetStats() - storeType := codec.GetStore().GetType() +// Recorder records metrics in prometheus by retrieving values from the codec channel +func (m *Prometheus) recorder() { + for codec := range m.codecChannel { + stats := codec.GetStats() + storeType := codec.GetStore().GetType() - m.Record(storeType, "hit_count", float64(stats.Hits)) - m.Record(storeType, "miss_count", float64(stats.Miss)) + m.record(storeType, "hit_count", float64(stats.Hits)) + m.record(storeType, "miss_count", float64(stats.Miss)) - m.Record(storeType, "set_success", float64(stats.SetSuccess)) - m.Record(storeType, "set_error", float64(stats.SetError)) + m.record(storeType, "set_success", float64(stats.SetSuccess)) + m.record(storeType, "set_error", float64(stats.SetError)) - m.Record(storeType, "delete_success", float64(stats.DeleteSuccess)) - m.Record(storeType, "delete_error", float64(stats.DeleteError)) + m.record(storeType, "delete_success", float64(stats.DeleteSuccess)) + m.record(storeType, "delete_error", float64(stats.DeleteError)) - m.Record(storeType, "invalidate_success", float64(stats.InvalidateSuccess)) - m.Record(storeType, "invalidate_error", float64(stats.InvalidateError)) + m.record(storeType, "invalidate_success", float64(stats.InvalidateSuccess)) + m.record(storeType, "invalidate_error", float64(stats.InvalidateError)) + } +} + +// RecordFromCodec sends the given codec into the codec channel to be read from recorder +func (m *Prometheus) RecordFromCodec(codec codec.CodecInterface) { + m.codecChannel <- codec } diff --git a/metrics/prometheus_test.go b/metrics/prometheus_test.go index 8e57ad0..de679bd 100644 --- a/metrics/prometheus_test.go +++ b/metrics/prometheus_test.go @@ -2,10 +2,12 @@ package metrics import ( "testing" + "time" "github.com/eko/gocache/codec" mocksCodec "github.com/eko/gocache/test/mocks/codec" mocksStore "github.com/eko/gocache/test/mocks/store" + "github.com/golang/mock/gomock" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/assert" @@ -21,7 +23,7 @@ func TestNewPrometheus(t *testing.T) { // Then assert.IsType(t, new(Prometheus), metrics) - assert.Equal(t, serviceName, metrics.name) + assert.Equal(t, serviceName, metrics.service) assert.IsType(t, new(prometheus.GaugeVec), metrics.collector) } @@ -30,7 +32,7 @@ func TestRecord(t *testing.T) { metrics := NewPrometheus("my-test-service-name") // When - metrics.Record("redis", "hit_count", 6) + metrics.record("redis", "hit_count", 6) // Then metric, err := metrics.collector.GetMetricWithLabelValues("my-test-service-name", "redis", "hit_count") @@ -44,8 +46,11 @@ func TestRecord(t *testing.T) { func TestRecordFromCodec(t *testing.T) { // Given - redisStore := &mocksStore.StoreInterface{} - redisStore.On("GetType").Return("redis") + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + redisStore := mocksStore.NewMockStoreInterface(ctrl) + redisStore.EXPECT().GetType().Return("redis") stats := &codec.Stats{ Hits: 4, @@ -58,15 +63,20 @@ func TestRecordFromCodec(t *testing.T) { InvalidateError: 1, } - testCodec := &mocksCodec.CodecInterface{} - testCodec.On("GetStats").Return(stats) - testCodec.On("GetStore").Return(redisStore) + testCodec := mocksCodec.NewMockCodecInterface(ctrl) + testCodec.EXPECT().GetStats().Return(stats) + testCodec.EXPECT().GetStore().Return(redisStore) metrics := NewPrometheus("my-test-service-name") // When metrics.RecordFromCodec(testCodec) + // Wait for data to be processed + for len(metrics.codecChannel) > 0 { + time.Sleep(1 * time.Millisecond) + } + // Then testCases := []struct { metricName string diff --git a/store/bigcache_test.go b/store/bigcache_test.go index ee77f3d..1d2b983 100644 --- a/store/bigcache_test.go +++ b/store/bigcache_test.go @@ -5,12 +5,16 @@ import ( "testing" mocksStore "github.com/eko/gocache/test/mocks/store/clients" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) func TestNewBigcache(t *testing.T) { // Given - client := &mocksStore.BigcacheClientInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockBigcacheClientInterface(ctrl) // When store := NewBigcache(client, nil) @@ -23,11 +27,14 @@ func TestNewBigcache(t *testing.T) { func TestBigcacheGet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.BigcacheClientInterface{} - client.On("Get", cacheKey).Return(cacheValue, nil) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Get(cacheKey).Return(cacheValue, nil) store := NewBigcache(client, nil) @@ -41,12 +48,15 @@ func TestBigcacheGet(t *testing.T) { func TestBigcacheGetWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" expectedErr := errors.New("An unexpected error occurred") - client := &mocksStore.BigcacheClientInterface{} - client.On("Get", cacheKey).Return(nil, expectedErr) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Get(cacheKey).Return(nil, expectedErr) store := NewBigcache(client, nil) @@ -60,13 +70,16 @@ func TestBigcacheGetWhenError(t *testing.T) { func TestBigcacheSet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") options := &Options{} - client := &mocksStore.BigcacheClientInterface{} - client.On("Set", cacheKey, cacheValue).Return(nil) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue).Return(nil) store := NewBigcache(client, nil) @@ -79,6 +92,9 @@ func TestBigcacheSet(t *testing.T) { func TestBigcacheSetWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") @@ -86,8 +102,8 @@ func TestBigcacheSetWhenError(t *testing.T) { expectedErr := errors.New("An unexpected error occurred") - client := &mocksStore.BigcacheClientInterface{} - client.On("Set", cacheKey, cacheValue).Return(expectedErr) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue).Return(expectedErr) store := NewBigcache(client, options) @@ -100,13 +116,16 @@ func TestBigcacheSetWhenError(t *testing.T) { func TestBigcacheSetWithTags(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.BigcacheClientInterface{} - client.On("Set", cacheKey, cacheValue).Return(nil) - client.On("Get", "gocache_tag_tag1").Return(nil, nil) - client.On("Set", "gocache_tag_tag1", []byte("my-key")).Return(nil) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue).Return(nil) + client.EXPECT().Get("gocache_tag_tag1").Return(nil, nil) + client.EXPECT().Set("gocache_tag_tag1", []byte("my-key")).Return(nil) store := NewBigcache(client, nil) @@ -119,13 +138,16 @@ func TestBigcacheSetWithTags(t *testing.T) { func TestBigcacheSetWithTagsWhenAlreadyInserted(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.BigcacheClientInterface{} - client.On("Set", cacheKey, cacheValue).Return(nil) - client.On("Get", "gocache_tag_tag1").Return([]byte("my-key,a-second-key"), nil) - client.On("Set", "gocache_tag_tag1", []byte("my-key,a-second-key")).Return(nil) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue).Return(nil) + client.EXPECT().Get("gocache_tag_tag1").Return([]byte("my-key,a-second-key"), nil) + client.EXPECT().Set("gocache_tag_tag1", []byte("my-key,a-second-key")).Return(nil) store := NewBigcache(client, nil) @@ -138,10 +160,13 @@ func TestBigcacheSetWithTagsWhenAlreadyInserted(t *testing.T) { func TestBigcacheDelete(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" - client := &mocksStore.BigcacheClientInterface{} - client.On("Delete", cacheKey).Return(nil) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Delete(cacheKey).Return(nil) store := NewBigcache(client, nil) @@ -154,12 +179,15 @@ func TestBigcacheDelete(t *testing.T) { func TestBigcacheDeleteWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to delete key") cacheKey := "my-key" - client := &mocksStore.BigcacheClientInterface{} - client.On("Delete", cacheKey).Return(expectedErr) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Delete(cacheKey).Return(expectedErr) store := NewBigcache(client, nil) @@ -172,16 +200,19 @@ func TestBigcacheDeleteWhenError(t *testing.T) { func TestBigcacheInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := InvalidateOptions{ Tags: []string{"tag1"}, } cacheKeys := []byte("a23fdf987h2svc23,jHG2372x38hf74") - client := &mocksStore.BigcacheClientInterface{} - client.On("Get", "gocache_tag_tag1").Return(cacheKeys, nil) - client.On("Delete", "a23fdf987h2svc23").Return(nil) - client.On("Delete", "jHG2372x38hf74").Return(nil) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Get("gocache_tag_tag1").Return(cacheKeys, nil) + client.EXPECT().Delete("a23fdf987h2svc23").Return(nil) + client.EXPECT().Delete("jHG2372x38hf74").Return(nil) store := NewBigcache(client, nil) @@ -194,16 +225,19 @@ func TestBigcacheInvalidate(t *testing.T) { func TestBigcacheInvalidateWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := InvalidateOptions{ Tags: []string{"tag1"}, } cacheKeys := []byte("a23fdf987h2svc23,jHG2372x38hf74") - client := &mocksStore.BigcacheClientInterface{} - client.On("Get", "gocache_tag_tag1").Return(cacheKeys, nil) - client.On("Delete", "a23fdf987h2svc23").Return(errors.New("Unexpected error")) - client.On("Delete", "jHG2372x38hf74").Return(nil) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Get("gocache_tag_tag1").Return(cacheKeys, nil) + client.EXPECT().Delete("a23fdf987h2svc23").Return(errors.New("Unexpected error")) + client.EXPECT().Delete("jHG2372x38hf74").Return(nil) store := NewBigcache(client, nil) @@ -216,8 +250,11 @@ func TestBigcacheInvalidateWhenError(t *testing.T) { func TestBigcacheClear(t *testing.T) { // Given - client := &mocksStore.BigcacheClientInterface{} - client.On("Reset").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Reset().Return(nil) store := NewBigcache(client, nil) @@ -230,10 +267,13 @@ func TestBigcacheClear(t *testing.T) { func TestBigcacheClearWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("An unexpected error occurred") - client := &mocksStore.BigcacheClientInterface{} - client.On("Reset").Return(expectedErr) + client := mocksStore.NewMockBigcacheClientInterface(ctrl) + client.EXPECT().Reset().Return(expectedErr) store := NewBigcache(client, nil) @@ -246,7 +286,10 @@ func TestBigcacheClearWhenError(t *testing.T) { func TestBigcacheGetType(t *testing.T) { // Given - client := &mocksStore.BigcacheClientInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockBigcacheClientInterface(ctrl) store := NewBigcache(client, nil) diff --git a/store/memcache_test.go b/store/memcache_test.go index c15450c..415ee10 100644 --- a/store/memcache_test.go +++ b/store/memcache_test.go @@ -7,13 +7,16 @@ import ( "github.com/bradfitz/gomemcache/memcache" mocksStore "github.com/eko/gocache/test/mocks/store/clients" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" - mock "github.com/stretchr/testify/mock" ) func TestNewMemcache(t *testing.T) { // Given - client := &mocksStore.MemcacheClientInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockMemcacheClientInterface(ctrl) options := &Options{Expiration: 3 * time.Second} // When @@ -27,13 +30,16 @@ func TestNewMemcache(t *testing.T) { func TestMemcacheGet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := &Options{Expiration: 3 * time.Second} cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.MemcacheClientInterface{} - client.On("Get", cacheKey).Return(&memcache.Item{ + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Get(cacheKey).Return(&memcache.Item{ Value: cacheValue, }, nil) @@ -49,14 +55,17 @@ func TestMemcacheGet(t *testing.T) { func TestMemcacheGetWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := &Options{Expiration: 3 * time.Second} cacheKey := "my-key" expectedErr := errors.New("An unexpected error occurred") - client := &mocksStore.MemcacheClientInterface{} - client.On("Get", cacheKey).Return(nil, expectedErr) + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Get(cacheKey).Return(nil, expectedErr) store := NewMemcache(client, options) @@ -70,13 +79,16 @@ func TestMemcacheGetWhenError(t *testing.T) { func TestMemcacheSet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := &Options{Expiration: 3 * time.Second} cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.MemcacheClientInterface{} - client.On("Set", &memcache.Item{ + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Set(&memcache.Item{ Key: cacheKey, Value: cacheValue, Expiration: int32(5), @@ -95,13 +107,16 @@ func TestMemcacheSet(t *testing.T) { func TestMemcacheSetWhenNoOptionsGiven(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := &Options{Expiration: 3 * time.Second} cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.MemcacheClientInterface{} - client.On("Set", &memcache.Item{ + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Set(&memcache.Item{ Key: cacheKey, Value: cacheValue, Expiration: int32(3), @@ -118,6 +133,9 @@ func TestMemcacheSetWhenNoOptionsGiven(t *testing.T) { func TestMemcacheSetWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := &Options{Expiration: 3 * time.Second} cacheKey := "my-key" @@ -125,8 +143,8 @@ func TestMemcacheSetWhenError(t *testing.T) { expectedErr := errors.New("An unexpected error occurred") - client := &mocksStore.MemcacheClientInterface{} - client.On("Set", &memcache.Item{ + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Set(&memcache.Item{ Key: cacheKey, Value: cacheValue, Expiration: int32(3), @@ -143,12 +161,15 @@ func TestMemcacheSetWhenError(t *testing.T) { func TestMemcacheSetWithTags(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.MemcacheClientInterface{} - client.On("Set", mock.Anything).Return(nil) - client.On("Get", "gocache_tag_tag1").Return(nil, nil) + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Set(gomock.Any()).AnyTimes().Return(nil) + client.EXPECT().Get("gocache_tag_tag1").Return(nil, nil) store := NewMemcache(client, nil) @@ -157,17 +178,19 @@ func TestMemcacheSetWithTags(t *testing.T) { // Then assert.Nil(t, err) - client.AssertNumberOfCalls(t, "Set", 2) } func TestMemcacheSetWithTagsWhenAlreadyInserted(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.MemcacheClientInterface{} - client.On("Set", mock.Anything).Return(nil) - client.On("Get", "gocache_tag_tag1").Return(&memcache.Item{ + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Set(gomock.Any()).AnyTimes().Return(nil) + client.EXPECT().Get("gocache_tag_tag1").Return(&memcache.Item{ Value: []byte("my-key,a-second-key"), }, nil) @@ -178,15 +201,17 @@ func TestMemcacheSetWithTagsWhenAlreadyInserted(t *testing.T) { // Then assert.Nil(t, err) - client.AssertNumberOfCalls(t, "Set", 2) } func TestMemcacheDelete(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" - client := &mocksStore.MemcacheClientInterface{} - client.On("Delete", cacheKey).Return(nil) + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Delete(cacheKey).Return(nil) store := NewMemcache(client, nil) @@ -199,12 +224,15 @@ func TestMemcacheDelete(t *testing.T) { func TestMemcacheDeleteWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("Unable to delete key") cacheKey := "my-key" - client := &mocksStore.MemcacheClientInterface{} - client.On("Delete", cacheKey).Return(expectedErr) + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Delete(cacheKey).Return(expectedErr) store := NewMemcache(client, nil) @@ -217,6 +245,9 @@ func TestMemcacheDeleteWhenError(t *testing.T) { func TestMemcacheInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := InvalidateOptions{ Tags: []string{"tag1"}, } @@ -225,10 +256,10 @@ func TestMemcacheInvalidate(t *testing.T) { Value: []byte("a23fdf987h2svc23,jHG2372x38hf74"), } - client := &mocksStore.MemcacheClientInterface{} - client.On("Get", "gocache_tag_tag1").Return(cacheKeys, nil) - client.On("Delete", "a23fdf987h2svc23").Return(nil) - client.On("Delete", "jHG2372x38hf74").Return(nil) + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Get("gocache_tag_tag1").Return(cacheKeys, nil) + client.EXPECT().Delete("a23fdf987h2svc23").Return(nil) + client.EXPECT().Delete("jHG2372x38hf74").Return(nil) store := NewMemcache(client, nil) @@ -241,6 +272,9 @@ func TestMemcacheInvalidate(t *testing.T) { func TestMemcacheInvalidateWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := InvalidateOptions{ Tags: []string{"tag1"}, } @@ -249,10 +283,10 @@ func TestMemcacheInvalidateWhenError(t *testing.T) { Value: []byte("a23fdf987h2svc23,jHG2372x38hf74"), } - client := &mocksStore.MemcacheClientInterface{} - client.On("Get", "gocache_tag_tag1").Return(cacheKeys, nil) - client.On("Delete", "a23fdf987h2svc23").Return(errors.New("Unexpected error")) - client.On("Delete", "jHG2372x38hf74").Return(nil) + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().Get("gocache_tag_tag1").Return(cacheKeys, nil) + client.EXPECT().Delete("a23fdf987h2svc23").Return(errors.New("Unexpected error")) + client.EXPECT().Delete("jHG2372x38hf74").Return(nil) store := NewMemcache(client, nil) @@ -265,8 +299,11 @@ func TestMemcacheInvalidateWhenError(t *testing.T) { func TestMemcacheClear(t *testing.T) { // Given - client := &mocksStore.MemcacheClientInterface{} - client.On("FlushAll").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().FlushAll().Return(nil) store := NewMemcache(client, nil) @@ -279,10 +316,13 @@ func TestMemcacheClear(t *testing.T) { func TestMemcacheClearWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + expectedErr := errors.New("An unexpected error occurred") - client := &mocksStore.MemcacheClientInterface{} - client.On("FlushAll").Return(expectedErr) + client := mocksStore.NewMockMemcacheClientInterface(ctrl) + client.EXPECT().FlushAll().Return(expectedErr) store := NewMemcache(client, nil) @@ -295,7 +335,10 @@ func TestMemcacheClearWhenError(t *testing.T) { func TestMemcacheGetType(t *testing.T) { // Given - client := &mocksStore.MemcacheClientInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockMemcacheClientInterface(ctrl) store := NewMemcache(client, nil) diff --git a/store/redis.go b/store/redis.go index 368f31b..469c5fd 100644 --- a/store/redis.go +++ b/store/redis.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "github.com/go-redis/redis/v7" + redis "github.com/go-redis/redis/v7" ) // RedisClientInterface represents a go-redis/redis client diff --git a/store/redis_test.go b/store/redis_test.go index bedba81..e474cf2 100644 --- a/store/redis_test.go +++ b/store/redis_test.go @@ -6,12 +6,16 @@ import ( mocksStore "github.com/eko/gocache/test/mocks/store/clients" "github.com/go-redis/redis/v7" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) func TestNewRedis(t *testing.T) { // Given - client := &mocksStore.RedisClientInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockRedisClientInterface(ctrl) options := &Options{ Expiration: 6 * time.Second, } @@ -27,8 +31,11 @@ func TestNewRedis(t *testing.T) { func TestRedisGet(t *testing.T) { // Given - client := &mocksStore.RedisClientInterface{} - client.On("Get", "my-key").Return(&redis.StringCmd{}) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockRedisClientInterface(ctrl) + client.EXPECT().Get("my-key").Return(&redis.StringCmd{}) store := NewRedis(client, nil) @@ -42,14 +49,17 @@ func TestRedisGet(t *testing.T) { func TestRedisSet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := "my-cache-value" options := &Options{ Expiration: 6 * time.Second, } - client := &mocksStore.RedisClientInterface{} - client.On("Set", "my-key", cacheValue, 5*time.Second).Return(&redis.StatusCmd{}) + client := mocksStore.NewMockRedisClientInterface(ctrl) + client.EXPECT().Set("my-key", cacheValue, 5*time.Second).Return(&redis.StatusCmd{}) store := NewRedis(client, options) @@ -64,14 +74,17 @@ func TestRedisSet(t *testing.T) { func TestRedisSetWhenNoOptionsGiven(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := "my-cache-value" options := &Options{ Expiration: 6 * time.Second, } - client := &mocksStore.RedisClientInterface{} - client.On("Set", "my-key", cacheValue, 6*time.Second).Return(&redis.StatusCmd{}) + client := mocksStore.NewMockRedisClientInterface(ctrl) + client.EXPECT().Set("my-key", cacheValue, 6*time.Second).Return(&redis.StatusCmd{}) store := NewRedis(client, options) @@ -84,13 +97,16 @@ func TestRedisSetWhenNoOptionsGiven(t *testing.T) { func TestRedisSetWithTags(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.RedisClientInterface{} - client.On("Set", cacheKey, cacheValue, time.Duration(0)).Return(&redis.StatusCmd{}) - client.On("Get", "gocache_tag_tag1").Return(&redis.StringCmd{}) - client.On("Set", "gocache_tag_tag1", []byte("my-key"), 720*time.Hour).Return(&redis.StatusCmd{}) + client := mocksStore.NewMockRedisClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue, time.Duration(0)).Return(&redis.StatusCmd{}) + client.EXPECT().Get("gocache_tag_tag1").Return(&redis.StringCmd{}) + client.EXPECT().Set("gocache_tag_tag1", []byte("my-key"), 720*time.Hour).Return(&redis.StatusCmd{}) store := NewRedis(client, nil) @@ -103,10 +119,13 @@ func TestRedisSetWithTags(t *testing.T) { func TestRedisDelete(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" - client := &mocksStore.RedisClientInterface{} - client.On("Del", "my-key").Return(&redis.IntCmd{}) + client := mocksStore.NewMockRedisClientInterface(ctrl) + client.EXPECT().Del("my-key").Return(&redis.IntCmd{}) store := NewRedis(client, nil) @@ -119,14 +138,17 @@ func TestRedisDelete(t *testing.T) { func TestRedisInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := InvalidateOptions{ Tags: []string{"tag1"}, } cacheKeys := &redis.StringCmd{} - client := &mocksStore.RedisClientInterface{} - client.On("Get", "gocache_tag_tag1").Return(cacheKeys, nil) + client := mocksStore.NewMockRedisClientInterface(ctrl) + client.EXPECT().Get("gocache_tag_tag1").Return(cacheKeys) store := NewRedis(client, nil) @@ -139,8 +161,11 @@ func TestRedisInvalidate(t *testing.T) { func TestRedisClear(t *testing.T) { // Given - client := &mocksStore.RedisClientInterface{} - client.On("FlushAll").Return(&redis.StatusCmd{}) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockRedisClientInterface(ctrl) + client.EXPECT().FlushAll().Return(&redis.StatusCmd{}) store := NewRedis(client, nil) @@ -153,7 +178,10 @@ func TestRedisClear(t *testing.T) { func TestRedisGetType(t *testing.T) { // Given - client := &mocksStore.RedisClientInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockRedisClientInterface(ctrl) store := NewRedis(client, nil) diff --git a/store/ristretto_test.go b/store/ristretto_test.go index 91e5c5e..472c94b 100644 --- a/store/ristretto_test.go +++ b/store/ristretto_test.go @@ -6,12 +6,16 @@ import ( "testing" mocksStore "github.com/eko/gocache/test/mocks/store/clients" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) func TestNewRistretto(t *testing.T) { // Given - client := &mocksStore.RistrettoClientInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockRistrettoClientInterface(ctrl) options := &Options{ Cost: 8, } @@ -27,11 +31,14 @@ func TestNewRistretto(t *testing.T) { func TestRistrettoGet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := "my-cache-value" - client := &mocksStore.RistrettoClientInterface{} - client.On("Get", cacheKey).Return(cacheValue, true) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Get(cacheKey).Return(cacheValue, true) store := NewRistretto(client, nil) @@ -45,10 +52,13 @@ func TestRistrettoGet(t *testing.T) { func TestRistrettoGetWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" - client := &mocksStore.RistrettoClientInterface{} - client.On("Get", cacheKey).Return(nil, false) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Get(cacheKey).Return(nil, false) store := NewRistretto(client, nil) @@ -62,14 +72,17 @@ func TestRistrettoGetWhenError(t *testing.T) { func TestRistrettoSet(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := "my-cache-value" options := &Options{ Cost: 7, } - client := &mocksStore.RistrettoClientInterface{} - client.On("Set", cacheKey, cacheValue, int64(4)).Return(true) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue, int64(4)).Return(true) store := NewRistretto(client, options) @@ -84,14 +97,17 @@ func TestRistrettoSet(t *testing.T) { func TestRistrettoSetWhenNoOptionsGiven(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := "my-cache-value" options := &Options{ Cost: 7, } - client := &mocksStore.RistrettoClientInterface{} - client.On("Set", cacheKey, cacheValue, int64(7)).Return(true) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue, int64(7)).Return(true) store := NewRistretto(client, options) @@ -104,14 +120,17 @@ func TestRistrettoSetWhenNoOptionsGiven(t *testing.T) { func TestRistrettoSetWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := "my-cache-value" options := &Options{ Cost: 7, } - client := &mocksStore.RistrettoClientInterface{} - client.On("Set", cacheKey, cacheValue, int64(7)).Return(false) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue, int64(7)).Return(false) store := NewRistretto(client, options) @@ -124,13 +143,16 @@ func TestRistrettoSetWhenError(t *testing.T) { func TestRistrettoSetWithTags(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.RistrettoClientInterface{} - client.On("Set", cacheKey, cacheValue, int64(0)).Return(true) - client.On("Get", "gocache_tag_tag1").Return(nil, true) - client.On("Set", "gocache_tag_tag1", []byte("my-key"), int64(0)).Return(true) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue, int64(0)).Return(true) + client.EXPECT().Get("gocache_tag_tag1").Return(nil, true) + client.EXPECT().Set("gocache_tag_tag1", []byte("my-key"), int64(0)).Return(true) store := NewRistretto(client, nil) @@ -143,13 +165,16 @@ func TestRistrettoSetWithTags(t *testing.T) { func TestRistrettoSetWithTagsWhenAlreadyInserted(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" cacheValue := []byte("my-cache-value") - client := &mocksStore.RistrettoClientInterface{} - client.On("Set", cacheKey, cacheValue, int64(0)).Return(true) - client.On("Get", "gocache_tag_tag1").Return([]byte("my-key,a-second-key"), true) - client.On("Set", "gocache_tag_tag1", []byte("my-key,a-second-key"), int64(0)).Return(true) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Set(cacheKey, cacheValue, int64(0)).Return(true) + client.EXPECT().Get("gocache_tag_tag1").Return([]byte("my-key,a-second-key"), true) + client.EXPECT().Set("gocache_tag_tag1", []byte("my-key,a-second-key"), int64(0)).Return(true) store := NewRistretto(client, nil) @@ -162,10 +187,13 @@ func TestRistrettoSetWithTagsWhenAlreadyInserted(t *testing.T) { func TestRistrettoDelete(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cacheKey := "my-key" - client := &mocksStore.RistrettoClientInterface{} - client.On("Del", cacheKey).Return(nil) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Del(cacheKey) store := NewRistretto(client, nil) @@ -178,16 +206,19 @@ func TestRistrettoDelete(t *testing.T) { func TestRistrettoInvalidate(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := InvalidateOptions{ Tags: []string{"tag1"}, } cacheKeys := []byte("a23fdf987h2svc23,jHG2372x38hf74") - client := &mocksStore.RistrettoClientInterface{} - client.On("Get", "gocache_tag_tag1").Return(cacheKeys, true) - client.On("Del", "a23fdf987h2svc23").Return(nil) - client.On("Del", "jHG2372x38hf74").Return(nil) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Get("gocache_tag_tag1").Return(cacheKeys, true) + client.EXPECT().Del("a23fdf987h2svc23") + client.EXPECT().Del("jHG2372x38hf74") store := NewRistretto(client, nil) @@ -200,16 +231,17 @@ func TestRistrettoInvalidate(t *testing.T) { func TestRistrettoInvalidateWhenError(t *testing.T) { // Given + ctrl := gomock.NewController(t) + defer ctrl.Finish() + options := InvalidateOptions{ Tags: []string{"tag1"}, } cacheKeys := []byte("a23fdf987h2svc23,jHG2372x38hf74") - client := &mocksStore.RistrettoClientInterface{} - client.On("Get", "gocache_tag_tag1").Return(cacheKeys, false) - client.On("Del", "a23fdf987h2svc23").Return(nil) - client.On("Del", "jHG2372x38hf74").Return(nil) + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Get("gocache_tag_tag1").Return(cacheKeys, false) store := NewRistretto(client, nil) @@ -222,8 +254,11 @@ func TestRistrettoInvalidateWhenError(t *testing.T) { func TestRistrettoClear(t *testing.T) { // Given - client := &mocksStore.RistrettoClientInterface{} - client.On("Clear").Return(nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockRistrettoClientInterface(ctrl) + client.EXPECT().Clear() store := NewRistretto(client, nil) @@ -236,7 +271,10 @@ func TestRistrettoClear(t *testing.T) { func TestRistrettoGetType(t *testing.T) { // Given - client := &mocksStore.RistrettoClientInterface{} + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mocksStore.NewMockRistrettoClientInterface(ctrl) store := NewRistretto(client, nil) diff --git a/test/mocks/cache/cache_interface.go b/test/mocks/cache/cache_interface.go index 077b5b4..9c1876a 100644 --- a/test/mocks/cache/cache_interface.go +++ b/test/mocks/cache/cache_interface.go @@ -1,104 +1,242 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by MockGen. DO NOT EDIT. +// Source: cache/interface.go +// Package mocks is a generated GoMock package. package mocks -import mock "github.com/stretchr/testify/mock" -import store "github.com/eko/gocache/store" +import ( + codec "github.com/eko/gocache/codec" + store "github.com/eko/gocache/store" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockCacheInterface is a mock of CacheInterface interface +type MockCacheInterface struct { + ctrl *gomock.Controller + recorder *MockCacheInterfaceMockRecorder +} + +// MockCacheInterfaceMockRecorder is the mock recorder for MockCacheInterface +type MockCacheInterfaceMockRecorder struct { + mock *MockCacheInterface +} + +// NewMockCacheInterface creates a new mock instance +func NewMockCacheInterface(ctrl *gomock.Controller) *MockCacheInterface { + mock := &MockCacheInterface{ctrl: ctrl} + mock.recorder = &MockCacheInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockCacheInterface) EXPECT() *MockCacheInterfaceMockRecorder { + return m.recorder +} + +// Get mocks base method +func (m *MockCacheInterface) Get(key interface{}) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", key) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get +func (mr *MockCacheInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockCacheInterface)(nil).Get), key) +} + +// Set mocks base method +func (m *MockCacheInterface) Set(key, object interface{}, options *store.Options) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", key, object, options) + ret0, _ := ret[0].(error) + return ret0 +} + +// Set indicates an expected call of Set +func (mr *MockCacheInterfaceMockRecorder) Set(key, object, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockCacheInterface)(nil).Set), key, object, options) +} + +// Delete mocks base method +func (m *MockCacheInterface) Delete(key interface{}) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", key) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete +func (mr *MockCacheInterfaceMockRecorder) Delete(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockCacheInterface)(nil).Delete), key) +} + +// Invalidate mocks base method +func (m *MockCacheInterface) Invalidate(options store.InvalidateOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Invalidate", options) + ret0, _ := ret[0].(error) + return ret0 +} + +// Invalidate indicates an expected call of Invalidate +func (mr *MockCacheInterfaceMockRecorder) Invalidate(options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Invalidate", reflect.TypeOf((*MockCacheInterface)(nil).Invalidate), options) +} + +// Clear mocks base method +func (m *MockCacheInterface) Clear() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Clear") + ret0, _ := ret[0].(error) + return ret0 +} -// CacheInterface is an autogenerated mock type for the CacheInterface type -type CacheInterface struct { - mock.Mock +// Clear indicates an expected call of Clear +func (mr *MockCacheInterfaceMockRecorder) Clear() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockCacheInterface)(nil).Clear)) } -// Clear provides a mock function with given fields: -func (_m *CacheInterface) Clear() error { - ret := _m.Called() +// GetType mocks base method +func (m *MockCacheInterface) GetType() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetType") + ret0, _ := ret[0].(string) + return ret0 +} - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } +// GetType indicates an expected call of GetType +func (mr *MockCacheInterfaceMockRecorder) GetType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetType", reflect.TypeOf((*MockCacheInterface)(nil).GetType)) +} - return r0 +// MockSetterCacheInterface is a mock of SetterCacheInterface interface +type MockSetterCacheInterface struct { + ctrl *gomock.Controller + recorder *MockSetterCacheInterfaceMockRecorder } -// Delete provides a mock function with given fields: key -func (_m *CacheInterface) Delete(key interface{}) error { - ret := _m.Called(key) +// MockSetterCacheInterfaceMockRecorder is the mock recorder for MockSetterCacheInterface +type MockSetterCacheInterfaceMockRecorder struct { + mock *MockSetterCacheInterface +} + +// NewMockSetterCacheInterface creates a new mock instance +func NewMockSetterCacheInterface(ctrl *gomock.Controller) *MockSetterCacheInterface { + mock := &MockSetterCacheInterface{ctrl: ctrl} + mock.recorder = &MockSetterCacheInterfaceMockRecorder{mock} + return mock +} - var r0 error - if rf, ok := ret.Get(0).(func(interface{}) error); ok { - r0 = rf(key) - } else { - r0 = ret.Error(0) - } +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockSetterCacheInterface) EXPECT() *MockSetterCacheInterfaceMockRecorder { + return m.recorder +} - return r0 +// Get mocks base method +func (m *MockSetterCacheInterface) Get(key interface{}) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", key) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// Get provides a mock function with given fields: key -func (_m *CacheInterface) Get(key interface{}) (interface{}, error) { - ret := _m.Called(key) +// Get indicates an expected call of Get +func (mr *MockSetterCacheInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockSetterCacheInterface)(nil).Get), key) +} - var r0 interface{} - if rf, ok := ret.Get(0).(func(interface{}) interface{}); ok { - r0 = rf(key) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) - } - } +// Set mocks base method +func (m *MockSetterCacheInterface) Set(key, object interface{}, options *store.Options) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", key, object, options) + ret0, _ := ret[0].(error) + return ret0 +} - var r1 error - if rf, ok := ret.Get(1).(func(interface{}) error); ok { - r1 = rf(key) - } else { - r1 = ret.Error(1) - } +// Set indicates an expected call of Set +func (mr *MockSetterCacheInterfaceMockRecorder) Set(key, object, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockSetterCacheInterface)(nil).Set), key, object, options) +} - return r0, r1 +// Delete mocks base method +func (m *MockSetterCacheInterface) Delete(key interface{}) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", key) + ret0, _ := ret[0].(error) + return ret0 } -// GetType provides a mock function with given fields: -func (_m *CacheInterface) GetType() string { - ret := _m.Called() +// Delete indicates an expected call of Delete +func (mr *MockSetterCacheInterfaceMockRecorder) Delete(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockSetterCacheInterface)(nil).Delete), key) +} - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } +// Invalidate mocks base method +func (m *MockSetterCacheInterface) Invalidate(options store.InvalidateOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Invalidate", options) + ret0, _ := ret[0].(error) + return ret0 +} - return r0 +// Invalidate indicates an expected call of Invalidate +func (mr *MockSetterCacheInterfaceMockRecorder) Invalidate(options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Invalidate", reflect.TypeOf((*MockSetterCacheInterface)(nil).Invalidate), options) } -// Invalidate provides a mock function with given fields: options -func (_m *CacheInterface) Invalidate(options store.InvalidateOptions) error { - ret := _m.Called(options) +// Clear mocks base method +func (m *MockSetterCacheInterface) Clear() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Clear") + ret0, _ := ret[0].(error) + return ret0 +} - var r0 error - if rf, ok := ret.Get(0).(func(store.InvalidateOptions) error); ok { - r0 = rf(options) - } else { - r0 = ret.Error(0) - } +// Clear indicates an expected call of Clear +func (mr *MockSetterCacheInterfaceMockRecorder) Clear() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockSetterCacheInterface)(nil).Clear)) +} - return r0 +// GetType mocks base method +func (m *MockSetterCacheInterface) GetType() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetType") + ret0, _ := ret[0].(string) + return ret0 } -// Set provides a mock function with given fields: key, object, options -func (_m *CacheInterface) Set(key interface{}, object interface{}, options *store.Options) error { - ret := _m.Called(key, object, options) +// GetType indicates an expected call of GetType +func (mr *MockSetterCacheInterfaceMockRecorder) GetType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetType", reflect.TypeOf((*MockSetterCacheInterface)(nil).GetType)) +} - var r0 error - if rf, ok := ret.Get(0).(func(interface{}, interface{}, *store.Options) error); ok { - r0 = rf(key, object, options) - } else { - r0 = ret.Error(0) - } +// GetCodec mocks base method +func (m *MockSetterCacheInterface) GetCodec() codec.CodecInterface { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCodec") + ret0, _ := ret[0].(codec.CodecInterface) + return ret0 +} - return r0 +// GetCodec indicates an expected call of GetCodec +func (mr *MockSetterCacheInterfaceMockRecorder) GetCodec() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCodec", reflect.TypeOf((*MockSetterCacheInterface)(nil).GetCodec)) } diff --git a/test/mocks/cache/setter_cache_interface.go b/test/mocks/cache/setter_cache_interface.go deleted file mode 100644 index 377435c..0000000 --- a/test/mocks/cache/setter_cache_interface.go +++ /dev/null @@ -1,121 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mocks - -import codec "github.com/eko/gocache/codec" -import mock "github.com/stretchr/testify/mock" -import store "github.com/eko/gocache/store" - -// SetterCacheInterface is an autogenerated mock type for the SetterCacheInterface type -type SetterCacheInterface struct { - mock.Mock -} - -// Clear provides a mock function with given fields: -func (_m *SetterCacheInterface) Clear() error { - ret := _m.Called() - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Delete provides a mock function with given fields: key -func (_m *SetterCacheInterface) Delete(key interface{}) error { - ret := _m.Called(key) - - var r0 error - if rf, ok := ret.Get(0).(func(interface{}) error); ok { - r0 = rf(key) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Get provides a mock function with given fields: key -func (_m *SetterCacheInterface) Get(key interface{}) (interface{}, error) { - ret := _m.Called(key) - - var r0 interface{} - if rf, ok := ret.Get(0).(func(interface{}) interface{}); ok { - r0 = rf(key) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(interface{}) error); ok { - r1 = rf(key) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GetCodec provides a mock function with given fields: -func (_m *SetterCacheInterface) GetCodec() codec.CodecInterface { - ret := _m.Called() - - var r0 codec.CodecInterface - if rf, ok := ret.Get(0).(func() codec.CodecInterface); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(codec.CodecInterface) - } - } - - return r0 -} - -// GetType provides a mock function with given fields: -func (_m *SetterCacheInterface) GetType() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// Invalidate provides a mock function with given fields: options -func (_m *SetterCacheInterface) Invalidate(options store.InvalidateOptions) error { - ret := _m.Called(options) - - var r0 error - if rf, ok := ret.Get(0).(func(store.InvalidateOptions) error); ok { - r0 = rf(options) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Set provides a mock function with given fields: key, object, options -func (_m *SetterCacheInterface) Set(key interface{}, object interface{}, options *store.Options) error { - ret := _m.Called(key, object, options) - - var r0 error - if rf, ok := ret.Get(0).(func(interface{}, interface{}, *store.Options) error); ok { - r0 = rf(key, object, options) - } else { - r0 = ret.Error(0) - } - - return r0 -} diff --git a/test/mocks/codec/codec_interface.go b/test/mocks/codec/codec_interface.go index 3a5a06a..bbb670d 100644 --- a/test/mocks/codec/codec_interface.go +++ b/test/mocks/codec/codec_interface.go @@ -1,123 +1,134 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by MockGen. DO NOT EDIT. +// Source: codec/interface.go +// Package mocks is a generated GoMock package. package mocks -import codec "github.com/eko/gocache/codec" -import mock "github.com/stretchr/testify/mock" -import store "github.com/eko/gocache/store" - -// CodecInterface is an autogenerated mock type for the CodecInterface type -type CodecInterface struct { - mock.Mock +import ( + codec "github.com/eko/gocache/codec" + store "github.com/eko/gocache/store" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockCodecInterface is a mock of CodecInterface interface +type MockCodecInterface struct { + ctrl *gomock.Controller + recorder *MockCodecInterfaceMockRecorder } -// Clear provides a mock function with given fields: -func (_m *CodecInterface) Clear() error { - ret := _m.Called() - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 +// MockCodecInterfaceMockRecorder is the mock recorder for MockCodecInterface +type MockCodecInterfaceMockRecorder struct { + mock *MockCodecInterface } -// Delete provides a mock function with given fields: key -func (_m *CodecInterface) Delete(key interface{}) error { - ret := _m.Called(key) - - var r0 error - if rf, ok := ret.Get(0).(func(interface{}) error); ok { - r0 = rf(key) - } else { - r0 = ret.Error(0) - } - - return r0 +// NewMockCodecInterface creates a new mock instance +func NewMockCodecInterface(ctrl *gomock.Controller) *MockCodecInterface { + mock := &MockCodecInterface{ctrl: ctrl} + mock.recorder = &MockCodecInterfaceMockRecorder{mock} + return mock } -// Get provides a mock function with given fields: key -func (_m *CodecInterface) Get(key interface{}) (interface{}, error) { - ret := _m.Called(key) - - var r0 interface{} - if rf, ok := ret.Get(0).(func(interface{}) interface{}); ok { - r0 = rf(key) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) - } - } +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockCodecInterface) EXPECT() *MockCodecInterfaceMockRecorder { + return m.recorder +} - var r1 error - if rf, ok := ret.Get(1).(func(interface{}) error); ok { - r1 = rf(key) - } else { - r1 = ret.Error(1) - } +// Get mocks base method +func (m *MockCodecInterface) Get(key interface{}) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", key) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} - return r0, r1 +// Get indicates an expected call of Get +func (mr *MockCodecInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockCodecInterface)(nil).Get), key) } -// GetStats provides a mock function with given fields: -func (_m *CodecInterface) GetStats() *codec.Stats { - ret := _m.Called() +// Set mocks base method +func (m *MockCodecInterface) Set(key, value interface{}, options *store.Options) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", key, value, options) + ret0, _ := ret[0].(error) + return ret0 +} - var r0 *codec.Stats - if rf, ok := ret.Get(0).(func() *codec.Stats); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*codec.Stats) - } - } +// Set indicates an expected call of Set +func (mr *MockCodecInterfaceMockRecorder) Set(key, value, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockCodecInterface)(nil).Set), key, value, options) +} - return r0 +// Delete mocks base method +func (m *MockCodecInterface) Delete(key interface{}) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", key) + ret0, _ := ret[0].(error) + return ret0 } -// GetStore provides a mock function with given fields: -func (_m *CodecInterface) GetStore() store.StoreInterface { - ret := _m.Called() +// Delete indicates an expected call of Delete +func (mr *MockCodecInterfaceMockRecorder) Delete(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockCodecInterface)(nil).Delete), key) +} - var r0 store.StoreInterface - if rf, ok := ret.Get(0).(func() store.StoreInterface); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreInterface) - } - } +// Invalidate mocks base method +func (m *MockCodecInterface) Invalidate(options store.InvalidateOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Invalidate", options) + ret0, _ := ret[0].(error) + return ret0 +} - return r0 +// Invalidate indicates an expected call of Invalidate +func (mr *MockCodecInterfaceMockRecorder) Invalidate(options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Invalidate", reflect.TypeOf((*MockCodecInterface)(nil).Invalidate), options) } -// Invalidate provides a mock function with given fields: options -func (_m *CodecInterface) Invalidate(options store.InvalidateOptions) error { - ret := _m.Called(options) +// Clear mocks base method +func (m *MockCodecInterface) Clear() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Clear") + ret0, _ := ret[0].(error) + return ret0 +} - var r0 error - if rf, ok := ret.Get(0).(func(store.InvalidateOptions) error); ok { - r0 = rf(options) - } else { - r0 = ret.Error(0) - } +// Clear indicates an expected call of Clear +func (mr *MockCodecInterfaceMockRecorder) Clear() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockCodecInterface)(nil).Clear)) +} - return r0 +// GetStore mocks base method +func (m *MockCodecInterface) GetStore() store.StoreInterface { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStore") + ret0, _ := ret[0].(store.StoreInterface) + return ret0 } -// Set provides a mock function with given fields: key, value, options -func (_m *CodecInterface) Set(key interface{}, value interface{}, options *store.Options) error { - ret := _m.Called(key, value, options) +// GetStore indicates an expected call of GetStore +func (mr *MockCodecInterfaceMockRecorder) GetStore() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStore", reflect.TypeOf((*MockCodecInterface)(nil).GetStore)) +} - var r0 error - if rf, ok := ret.Get(0).(func(interface{}, interface{}, *store.Options) error); ok { - r0 = rf(key, value, options) - } else { - r0 = ret.Error(0) - } +// GetStats mocks base method +func (m *MockCodecInterface) GetStats() *codec.Stats { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStats") + ret0, _ := ret[0].(*codec.Stats) + return ret0 +} - return r0 +// GetStats indicates an expected call of GetStats +func (mr *MockCodecInterfaceMockRecorder) GetStats() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStats", reflect.TypeOf((*MockCodecInterface)(nil).GetStats)) } diff --git a/test/mocks/metrics/metrics_interface.go b/test/mocks/metrics/metrics_interface.go index 470b3a9..bb2eda5 100644 --- a/test/mocks/metrics/metrics_interface.go +++ b/test/mocks/metrics/metrics_interface.go @@ -1,22 +1,46 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by MockGen. DO NOT EDIT. +// Source: metrics/interface.go +// Package mocks is a generated GoMock package. package mocks -import codec "github.com/eko/gocache/codec" +import ( + codec "github.com/eko/gocache/codec" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) -import mock "github.com/stretchr/testify/mock" +// MockMetricsInterface is a mock of MetricsInterface interface +type MockMetricsInterface struct { + ctrl *gomock.Controller + recorder *MockMetricsInterfaceMockRecorder +} + +// MockMetricsInterfaceMockRecorder is the mock recorder for MockMetricsInterface +type MockMetricsInterfaceMockRecorder struct { + mock *MockMetricsInterface +} + +// NewMockMetricsInterface creates a new mock instance +func NewMockMetricsInterface(ctrl *gomock.Controller) *MockMetricsInterface { + mock := &MockMetricsInterface{ctrl: ctrl} + mock.recorder = &MockMetricsInterfaceMockRecorder{mock} + return mock +} -// MetricsInterface is an autogenerated mock type for the MetricsInterface type -type MetricsInterface struct { - mock.Mock +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockMetricsInterface) EXPECT() *MockMetricsInterfaceMockRecorder { + return m.recorder } -// Record provides a mock function with given fields: store, metric, value -func (_m *MetricsInterface) Record(store string, metric string, value float64) { - _m.Called(store, metric, value) +// RecordFromCodec mocks base method +func (m *MockMetricsInterface) RecordFromCodec(codec codec.CodecInterface) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RecordFromCodec", codec) } -// RecordFromCodec provides a mock function with given fields: _a0 -func (_m *MetricsInterface) RecordFromCodec(_a0 codec.CodecInterface) { - _m.Called(_a0) +// RecordFromCodec indicates an expected call of RecordFromCodec +func (mr *MockMetricsInterfaceMockRecorder) RecordFromCodec(codec interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordFromCodec", reflect.TypeOf((*MockMetricsInterface)(nil).RecordFromCodec), codec) } diff --git a/test/mocks/store/clients/bigcache_client_interface.go b/test/mocks/store/clients/bigcache_client_interface.go deleted file mode 100644 index 367777f..0000000 --- a/test/mocks/store/clients/bigcache_client_interface.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mocks - -import mock "github.com/stretchr/testify/mock" - -// BigcacheClientInterface is an autogenerated mock type for the BigcacheClientInterface type -type BigcacheClientInterface struct { - mock.Mock -} - -// Delete provides a mock function with given fields: key -func (_m *BigcacheClientInterface) Delete(key string) error { - ret := _m.Called(key) - - var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { - r0 = rf(key) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Get provides a mock function with given fields: key -func (_m *BigcacheClientInterface) Get(key string) ([]byte, error) { - ret := _m.Called(key) - - var r0 []byte - if rf, ok := ret.Get(0).(func(string) []byte); ok { - r0 = rf(key) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(key) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Reset provides a mock function with given fields: -func (_m *BigcacheClientInterface) Reset() error { - ret := _m.Called() - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Set provides a mock function with given fields: key, entry -func (_m *BigcacheClientInterface) Set(key string, entry []byte) error { - ret := _m.Called(key, entry) - - var r0 error - if rf, ok := ret.Get(0).(func(string, []byte) error); ok { - r0 = rf(key, entry) - } else { - r0 = ret.Error(0) - } - - return r0 -} diff --git a/test/mocks/store/clients/bigcache_interface.go b/test/mocks/store/clients/bigcache_interface.go new file mode 100644 index 0000000..7d600f1 --- /dev/null +++ b/test/mocks/store/clients/bigcache_interface.go @@ -0,0 +1,90 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: store/bigcache.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockBigcacheClientInterface is a mock of BigcacheClientInterface interface +type MockBigcacheClientInterface struct { + ctrl *gomock.Controller + recorder *MockBigcacheClientInterfaceMockRecorder +} + +// MockBigcacheClientInterfaceMockRecorder is the mock recorder for MockBigcacheClientInterface +type MockBigcacheClientInterfaceMockRecorder struct { + mock *MockBigcacheClientInterface +} + +// NewMockBigcacheClientInterface creates a new mock instance +func NewMockBigcacheClientInterface(ctrl *gomock.Controller) *MockBigcacheClientInterface { + mock := &MockBigcacheClientInterface{ctrl: ctrl} + mock.recorder = &MockBigcacheClientInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockBigcacheClientInterface) EXPECT() *MockBigcacheClientInterfaceMockRecorder { + return m.recorder +} + +// Get mocks base method +func (m *MockBigcacheClientInterface) Get(key string) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", key) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get +func (mr *MockBigcacheClientInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockBigcacheClientInterface)(nil).Get), key) +} + +// Set mocks base method +func (m *MockBigcacheClientInterface) Set(key string, entry []byte) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", key, entry) + ret0, _ := ret[0].(error) + return ret0 +} + +// Set indicates an expected call of Set +func (mr *MockBigcacheClientInterfaceMockRecorder) Set(key, entry interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockBigcacheClientInterface)(nil).Set), key, entry) +} + +// Delete mocks base method +func (m *MockBigcacheClientInterface) Delete(key string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", key) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete +func (mr *MockBigcacheClientInterfaceMockRecorder) Delete(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockBigcacheClientInterface)(nil).Delete), key) +} + +// Reset mocks base method +func (m *MockBigcacheClientInterface) Reset() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Reset") + ret0, _ := ret[0].(error) + return ret0 +} + +// Reset indicates an expected call of Reset +func (mr *MockBigcacheClientInterfaceMockRecorder) Reset() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reset", reflect.TypeOf((*MockBigcacheClientInterface)(nil).Reset)) +} diff --git a/test/mocks/store/clients/memcache_client_interface.go b/test/mocks/store/clients/memcache_client_interface.go deleted file mode 100644 index dcfa821..0000000 --- a/test/mocks/store/clients/memcache_client_interface.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mocks - -import memcache "github.com/bradfitz/gomemcache/memcache" -import mock "github.com/stretchr/testify/mock" - -// MemcacheClientInterface is an autogenerated mock type for the MemcacheClientInterface type -type MemcacheClientInterface struct { - mock.Mock -} - -// Delete provides a mock function with given fields: item -func (_m *MemcacheClientInterface) Delete(item string) error { - ret := _m.Called(item) - - var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { - r0 = rf(item) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// FlushAll provides a mock function with given fields: -func (_m *MemcacheClientInterface) FlushAll() error { - ret := _m.Called() - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Get provides a mock function with given fields: key -func (_m *MemcacheClientInterface) Get(key string) (*memcache.Item, error) { - ret := _m.Called(key) - - var r0 *memcache.Item - if rf, ok := ret.Get(0).(func(string) *memcache.Item); ok { - r0 = rf(key) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*memcache.Item) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(key) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Set provides a mock function with given fields: item -func (_m *MemcacheClientInterface) Set(item *memcache.Item) error { - ret := _m.Called(item) - - var r0 error - if rf, ok := ret.Get(0).(func(*memcache.Item) error); ok { - r0 = rf(item) - } else { - r0 = ret.Error(0) - } - - return r0 -} diff --git a/test/mocks/store/clients/memcache_interface.go b/test/mocks/store/clients/memcache_interface.go new file mode 100644 index 0000000..5f0945e --- /dev/null +++ b/test/mocks/store/clients/memcache_interface.go @@ -0,0 +1,91 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: store/memcache.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + memcache "github.com/bradfitz/gomemcache/memcache" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockMemcacheClientInterface is a mock of MemcacheClientInterface interface +type MockMemcacheClientInterface struct { + ctrl *gomock.Controller + recorder *MockMemcacheClientInterfaceMockRecorder +} + +// MockMemcacheClientInterfaceMockRecorder is the mock recorder for MockMemcacheClientInterface +type MockMemcacheClientInterfaceMockRecorder struct { + mock *MockMemcacheClientInterface +} + +// NewMockMemcacheClientInterface creates a new mock instance +func NewMockMemcacheClientInterface(ctrl *gomock.Controller) *MockMemcacheClientInterface { + mock := &MockMemcacheClientInterface{ctrl: ctrl} + mock.recorder = &MockMemcacheClientInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockMemcacheClientInterface) EXPECT() *MockMemcacheClientInterfaceMockRecorder { + return m.recorder +} + +// Get mocks base method +func (m *MockMemcacheClientInterface) Get(key string) (*memcache.Item, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", key) + ret0, _ := ret[0].(*memcache.Item) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get +func (mr *MockMemcacheClientInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockMemcacheClientInterface)(nil).Get), key) +} + +// Set mocks base method +func (m *MockMemcacheClientInterface) Set(item *memcache.Item) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", item) + ret0, _ := ret[0].(error) + return ret0 +} + +// Set indicates an expected call of Set +func (mr *MockMemcacheClientInterfaceMockRecorder) Set(item interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockMemcacheClientInterface)(nil).Set), item) +} + +// Delete mocks base method +func (m *MockMemcacheClientInterface) Delete(item string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", item) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete +func (mr *MockMemcacheClientInterfaceMockRecorder) Delete(item interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockMemcacheClientInterface)(nil).Delete), item) +} + +// FlushAll mocks base method +func (m *MockMemcacheClientInterface) FlushAll() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FlushAll") + ret0, _ := ret[0].(error) + return ret0 +} + +// FlushAll indicates an expected call of FlushAll +func (mr *MockMemcacheClientInterfaceMockRecorder) FlushAll() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FlushAll", reflect.TypeOf((*MockMemcacheClientInterface)(nil).FlushAll)) +} diff --git a/test/mocks/store/clients/redis_client_interface.go b/test/mocks/store/clients/redis_client_interface.go deleted file mode 100644 index a52805d..0000000 --- a/test/mocks/store/clients/redis_client_interface.go +++ /dev/null @@ -1,83 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mocks - -import mock "github.com/stretchr/testify/mock" -import redis "github.com/go-redis/redis/v7" - -import time "time" - -// RedisClientInterface is an autogenerated mock type for the RedisClientInterface type -type RedisClientInterface struct { - mock.Mock -} - -// Del provides a mock function with given fields: keys -func (_m *RedisClientInterface) Del(keys ...string) *redis.IntCmd { - _va := make([]interface{}, len(keys)) - for _i := range keys { - _va[_i] = keys[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *redis.IntCmd - if rf, ok := ret.Get(0).(func(...string) *redis.IntCmd); ok { - r0 = rf(keys...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*redis.IntCmd) - } - } - - return r0 -} - -// FlushAll provides a mock function with given fields: -func (_m *RedisClientInterface) FlushAll() *redis.StatusCmd { - ret := _m.Called() - - var r0 *redis.StatusCmd - if rf, ok := ret.Get(0).(func() *redis.StatusCmd); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*redis.StatusCmd) - } - } - - return r0 -} - -// Get provides a mock function with given fields: key -func (_m *RedisClientInterface) Get(key string) *redis.StringCmd { - ret := _m.Called(key) - - var r0 *redis.StringCmd - if rf, ok := ret.Get(0).(func(string) *redis.StringCmd); ok { - r0 = rf(key) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*redis.StringCmd) - } - } - - return r0 -} - -// Set provides a mock function with given fields: key, value, expiration -func (_m *RedisClientInterface) Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd { - ret := _m.Called(key, value, expiration) - - var r0 *redis.StatusCmd - if rf, ok := ret.Get(0).(func(string, interface{}, time.Duration) *redis.StatusCmd); ok { - r0 = rf(key, value, expiration) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*redis.StatusCmd) - } - } - - return r0 -} diff --git a/test/mocks/store/clients/redis_interface.go b/test/mocks/store/clients/redis_interface.go new file mode 100644 index 0000000..85d44fe --- /dev/null +++ b/test/mocks/store/clients/redis_interface.go @@ -0,0 +1,95 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: store/redis.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + v7 "github.com/go-redis/redis/v7" + gomock "github.com/golang/mock/gomock" + reflect "reflect" + time "time" +) + +// MockRedisClientInterface is a mock of RedisClientInterface interface +type MockRedisClientInterface struct { + ctrl *gomock.Controller + recorder *MockRedisClientInterfaceMockRecorder +} + +// MockRedisClientInterfaceMockRecorder is the mock recorder for MockRedisClientInterface +type MockRedisClientInterfaceMockRecorder struct { + mock *MockRedisClientInterface +} + +// NewMockRedisClientInterface creates a new mock instance +func NewMockRedisClientInterface(ctrl *gomock.Controller) *MockRedisClientInterface { + mock := &MockRedisClientInterface{ctrl: ctrl} + mock.recorder = &MockRedisClientInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockRedisClientInterface) EXPECT() *MockRedisClientInterfaceMockRecorder { + return m.recorder +} + +// Get mocks base method +func (m *MockRedisClientInterface) Get(key string) *v7.StringCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", key) + ret0, _ := ret[0].(*v7.StringCmd) + return ret0 +} + +// Get indicates an expected call of Get +func (mr *MockRedisClientInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRedisClientInterface)(nil).Get), key) +} + +// Set mocks base method +func (m *MockRedisClientInterface) Set(key string, value interface{}, expiration time.Duration) *v7.StatusCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", key, value, expiration) + ret0, _ := ret[0].(*v7.StatusCmd) + return ret0 +} + +// Set indicates an expected call of Set +func (mr *MockRedisClientInterfaceMockRecorder) Set(key, value, expiration interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockRedisClientInterface)(nil).Set), key, value, expiration) +} + +// Del mocks base method +func (m *MockRedisClientInterface) Del(keys ...string) *v7.IntCmd { + m.ctrl.T.Helper() + varargs := []interface{}{} + for _, a := range keys { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Del", varargs...) + ret0, _ := ret[0].(*v7.IntCmd) + return ret0 +} + +// Del indicates an expected call of Del +func (mr *MockRedisClientInterfaceMockRecorder) Del(keys ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Del", reflect.TypeOf((*MockRedisClientInterface)(nil).Del), keys...) +} + +// FlushAll mocks base method +func (m *MockRedisClientInterface) FlushAll() *v7.StatusCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FlushAll") + ret0, _ := ret[0].(*v7.StatusCmd) + return ret0 +} + +// FlushAll indicates an expected call of FlushAll +func (mr *MockRedisClientInterfaceMockRecorder) FlushAll() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FlushAll", reflect.TypeOf((*MockRedisClientInterface)(nil).FlushAll)) +} diff --git a/test/mocks/store/clients/ristretto_client_interface.go b/test/mocks/store/clients/ristretto_client_interface.go deleted file mode 100644 index 02be9e7..0000000 --- a/test/mocks/store/clients/ristretto_client_interface.go +++ /dev/null @@ -1,57 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mocks - -import mock "github.com/stretchr/testify/mock" - -// RistrettoClientInterface is an autogenerated mock type for the RistrettoClientInterface type -type RistrettoClientInterface struct { - mock.Mock -} - -// Clear provides a mock function with given fields: -func (_m *RistrettoClientInterface) Clear() { - _m.Called() -} - -// Del provides a mock function with given fields: key -func (_m *RistrettoClientInterface) Del(key interface{}) { - _m.Called(key) -} - -// Get provides a mock function with given fields: key -func (_m *RistrettoClientInterface) Get(key interface{}) (interface{}, bool) { - ret := _m.Called(key) - - var r0 interface{} - if rf, ok := ret.Get(0).(func(interface{}) interface{}); ok { - r0 = rf(key) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) - } - } - - var r1 bool - if rf, ok := ret.Get(1).(func(interface{}) bool); ok { - r1 = rf(key) - } else { - r1 = ret.Get(1).(bool) - } - - return r0, r1 -} - -// Set provides a mock function with given fields: key, value, cost -func (_m *RistrettoClientInterface) Set(key interface{}, value interface{}, cost int64) bool { - ret := _m.Called(key, value, cost) - - var r0 bool - if rf, ok := ret.Get(0).(func(interface{}, interface{}, int64) bool); ok { - r0 = rf(key, value, cost) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} diff --git a/test/mocks/store/clients/ristretto_interface.go b/test/mocks/store/clients/ristretto_interface.go new file mode 100644 index 0000000..e1e1275 --- /dev/null +++ b/test/mocks/store/clients/ristretto_interface.go @@ -0,0 +1,86 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: store/ristretto.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockRistrettoClientInterface is a mock of RistrettoClientInterface interface +type MockRistrettoClientInterface struct { + ctrl *gomock.Controller + recorder *MockRistrettoClientInterfaceMockRecorder +} + +// MockRistrettoClientInterfaceMockRecorder is the mock recorder for MockRistrettoClientInterface +type MockRistrettoClientInterfaceMockRecorder struct { + mock *MockRistrettoClientInterface +} + +// NewMockRistrettoClientInterface creates a new mock instance +func NewMockRistrettoClientInterface(ctrl *gomock.Controller) *MockRistrettoClientInterface { + mock := &MockRistrettoClientInterface{ctrl: ctrl} + mock.recorder = &MockRistrettoClientInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockRistrettoClientInterface) EXPECT() *MockRistrettoClientInterfaceMockRecorder { + return m.recorder +} + +// Get mocks base method +func (m *MockRistrettoClientInterface) Get(key interface{}) (interface{}, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", key) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// Get indicates an expected call of Get +func (mr *MockRistrettoClientInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRistrettoClientInterface)(nil).Get), key) +} + +// Set mocks base method +func (m *MockRistrettoClientInterface) Set(key, value interface{}, cost int64) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", key, value, cost) + ret0, _ := ret[0].(bool) + return ret0 +} + +// Set indicates an expected call of Set +func (mr *MockRistrettoClientInterfaceMockRecorder) Set(key, value, cost interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockRistrettoClientInterface)(nil).Set), key, value, cost) +} + +// Del mocks base method +func (m *MockRistrettoClientInterface) Del(key interface{}) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Del", key) +} + +// Del indicates an expected call of Del +func (mr *MockRistrettoClientInterfaceMockRecorder) Del(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Del", reflect.TypeOf((*MockRistrettoClientInterface)(nil).Del), key) +} + +// Clear mocks base method +func (m *MockRistrettoClientInterface) Clear() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Clear") +} + +// Clear indicates an expected call of Clear +func (mr *MockRistrettoClientInterfaceMockRecorder) Clear() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockRistrettoClientInterface)(nil).Clear)) +} diff --git a/test/mocks/store/store_interface.go b/test/mocks/store/store_interface.go index 1d8be68..7fd26b5 100644 --- a/test/mocks/store/store_interface.go +++ b/test/mocks/store/store_interface.go @@ -1,104 +1,119 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by MockGen. DO NOT EDIT. +// Source: store/interface.go +// Package mocks is a generated GoMock package. package mocks -import mock "github.com/stretchr/testify/mock" -import store "github.com/eko/gocache/store" +import ( + store "github.com/eko/gocache/store" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) -// StoreInterface is an autogenerated mock type for the StoreInterface type -type StoreInterface struct { - mock.Mock +// MockStoreInterface is a mock of StoreInterface interface +type MockStoreInterface struct { + ctrl *gomock.Controller + recorder *MockStoreInterfaceMockRecorder } -// Clear provides a mock function with given fields: -func (_m *StoreInterface) Clear() error { - ret := _m.Called() - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 +// MockStoreInterfaceMockRecorder is the mock recorder for MockStoreInterface +type MockStoreInterfaceMockRecorder struct { + mock *MockStoreInterface } -// Delete provides a mock function with given fields: key -func (_m *StoreInterface) Delete(key interface{}) error { - ret := _m.Called(key) - - var r0 error - if rf, ok := ret.Get(0).(func(interface{}) error); ok { - r0 = rf(key) - } else { - r0 = ret.Error(0) - } - - return r0 +// NewMockStoreInterface creates a new mock instance +func NewMockStoreInterface(ctrl *gomock.Controller) *MockStoreInterface { + mock := &MockStoreInterface{ctrl: ctrl} + mock.recorder = &MockStoreInterfaceMockRecorder{mock} + return mock } -// Get provides a mock function with given fields: key -func (_m *StoreInterface) Get(key interface{}) (interface{}, error) { - ret := _m.Called(key) +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockStoreInterface) EXPECT() *MockStoreInterfaceMockRecorder { + return m.recorder +} - var r0 interface{} - if rf, ok := ret.Get(0).(func(interface{}) interface{}); ok { - r0 = rf(key) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) - } - } +// Get mocks base method +func (m *MockStoreInterface) Get(key interface{}) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", key) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} - var r1 error - if rf, ok := ret.Get(1).(func(interface{}) error); ok { - r1 = rf(key) - } else { - r1 = ret.Error(1) - } +// Get indicates an expected call of Get +func (mr *MockStoreInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockStoreInterface)(nil).Get), key) +} - return r0, r1 +// Set mocks base method +func (m *MockStoreInterface) Set(key, value interface{}, options *store.Options) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", key, value, options) + ret0, _ := ret[0].(error) + return ret0 } -// GetType provides a mock function with given fields: -func (_m *StoreInterface) GetType() string { - ret := _m.Called() +// Set indicates an expected call of Set +func (mr *MockStoreInterfaceMockRecorder) Set(key, value, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockStoreInterface)(nil).Set), key, value, options) +} - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } +// Delete mocks base method +func (m *MockStoreInterface) Delete(key interface{}) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", key) + ret0, _ := ret[0].(error) + return ret0 +} - return r0 +// Delete indicates an expected call of Delete +func (mr *MockStoreInterfaceMockRecorder) Delete(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockStoreInterface)(nil).Delete), key) } -// Invalidate provides a mock function with given fields: options -func (_m *StoreInterface) Invalidate(options store.InvalidateOptions) error { - ret := _m.Called(options) +// Invalidate mocks base method +func (m *MockStoreInterface) Invalidate(options store.InvalidateOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Invalidate", options) + ret0, _ := ret[0].(error) + return ret0 +} - var r0 error - if rf, ok := ret.Get(0).(func(store.InvalidateOptions) error); ok { - r0 = rf(options) - } else { - r0 = ret.Error(0) - } +// Invalidate indicates an expected call of Invalidate +func (mr *MockStoreInterfaceMockRecorder) Invalidate(options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Invalidate", reflect.TypeOf((*MockStoreInterface)(nil).Invalidate), options) +} - return r0 +// Clear mocks base method +func (m *MockStoreInterface) Clear() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Clear") + ret0, _ := ret[0].(error) + return ret0 } -// Set provides a mock function with given fields: key, value, options -func (_m *StoreInterface) Set(key interface{}, value interface{}, options *store.Options) error { - ret := _m.Called(key, value, options) +// Clear indicates an expected call of Clear +func (mr *MockStoreInterfaceMockRecorder) Clear() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockStoreInterface)(nil).Clear)) +} - var r0 error - if rf, ok := ret.Get(0).(func(interface{}, interface{}, *store.Options) error); ok { - r0 = rf(key, value, options) - } else { - r0 = ret.Error(0) - } +// GetType mocks base method +func (m *MockStoreInterface) GetType() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetType") + ret0, _ := ret[0].(string) + return ret0 +} - return r0 +// GetType indicates an expected call of GetType +func (mr *MockStoreInterfaceMockRecorder) GetType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetType", reflect.TypeOf((*MockStoreInterface)(nil).GetType)) }