Skip to content

Commit

Permalink
Merge pull request #152 from eko/lowercase-errors
Browse files Browse the repository at this point in the history
Updated error messages to be in lowercase
  • Loading branch information
eko committed Jun 14, 2022
2 parents 28e850b + 4141a39 commit 60d868f
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 58 deletions.
12 changes: 6 additions & 6 deletions cache/cache_test.go
Expand Up @@ -65,7 +65,7 @@ func TestCacheSetWhenErrorOccurs(t *testing.T) {
Hello: "world",
}

storeErr := errors.New("An error has occurred while inserting data into store")
storeErr := errors.New("an error has occurred while inserting data into store")

mockedStore := mocksStore.NewMockStoreInterface(ctrl)
mockedStore.EXPECT().Set(ctx, "my-key", value, store.OptionsMatcher{
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestCacheGetWhenNotFound(t *testing.T) {

ctx := context.Background()

returnedErr := errors.New("Unable to find item in store")
returnedErr := errors.New("unable to find item in store")

store := mocksStore.NewMockStoreInterface(ctrl)
store.EXPECT().Get(ctx, "my-key").Return(nil, returnedErr)
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestCacheGetWithTTLWhenNotFound(t *testing.T) {

ctx := context.Background()

returnedErr := errors.New("Unable to find item in store")
returnedErr := errors.New("unable to find item in store")
expiration := 0 * time.Second

store := mocksStore.NewMockStoreInterface(ctrl)
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestCacheInvalidateWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error during invalidation")
expectedErr := errors.New("unexpected error during invalidation")

mockedStore := mocksStore.NewMockStoreInterface(ctrl)
mockedStore.EXPECT().Invalidate(ctx, store.InvalidateOptionsMatcher{
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestCacheClearWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error during invalidation")
expectedErr := errors.New("unexpected error during invalidation")

store := mocksStore.NewMockStoreInterface(ctrl)
store.EXPECT().Clear(ctx).Return(expectedErr)
Expand All @@ -367,7 +367,7 @@ func TestCacheDeleteWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unable to delete key")
expectedErr := errors.New("unable to delete key")

store := mocksStore.NewMockStoreInterface(ctrl)
store.EXPECT().Delete(ctx, "my-key").Return(expectedErr)
Expand Down
20 changes: 10 additions & 10 deletions cache/chain_test.go
Expand Up @@ -112,7 +112,7 @@ func TestChainGetWhenAvailableInSecondCache(t *testing.T) {
cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().GetCodec().AnyTimes().Return(codec1)
cache1.EXPECT().GetWithTTL(ctx, "my-key").Return(nil, 0*time.Second,
errors.New("Unable to find in cache 1"))
errors.New("unable to find in cache 1"))
cache1.EXPECT().Set(ctx, "my-key", cacheValue, &store.OptionsMatcher{}).AnyTimes().Return(nil)

// Cache 2
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestChainGetWhenNotAvailableInAnyCache(t *testing.T) {
cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().GetCodec().Return(codec1)
cache1.EXPECT().GetWithTTL(ctx, "my-key").Return(nil, 0*time.Second,
errors.New("Unable to find in cache 1"))
errors.New("unable to find in cache 1"))

// Cache 2
store2 := mocksStore.NewMockStoreInterface(ctrl)
Expand All @@ -168,7 +168,7 @@ func TestChainGetWhenNotAvailableInAnyCache(t *testing.T) {
cache2 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache2.EXPECT().GetCodec().Return(codec2)
cache2.EXPECT().GetWithTTL(ctx, "my-key").Return(nil, 0*time.Second,
errors.New("Unable to find in cache 2"))
errors.New("unable to find in cache 2"))

cache := NewChain[any](cache1, cache2)

Expand All @@ -179,7 +179,7 @@ func TestChainGetWhenNotAvailableInAnyCache(t *testing.T) {
time.Sleep(100 * time.Millisecond)

// Then
assert.Equal(t, errors.New("Unable to find in cache 2"), err)
assert.Equal(t, errors.New("unable to find in cache 2"), err)
assert.Equal(t, nil, value)
}

Expand Down Expand Up @@ -224,7 +224,7 @@ func TestChainSetWhenErrorOnSetting(t *testing.T) {
Hello: "world",
}

expectedErr := errors.New("An unexpected error occurred while setting data")
expectedErr := errors.New("an unexpected error occurred while setting data")

// Cache 1
store1 := mocksStore.NewMockStoreInterface(ctrl)
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestChainDeleteWhenError(t *testing.T) {

// Cache 1
cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Delete(ctx, "my-key").Return(errors.New("An error has occurred while deleting key"))
cache1.EXPECT().Delete(ctx, "my-key").Return(errors.New("an error has occurred while deleting key"))

// Cache 2
cache2 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestChainInvalidateWhenError(t *testing.T) {

// Cache 1
cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Invalidate(ctx).Return(errors.New("An unexpected error has occurred while invalidation data"))
cache1.EXPECT().Invalidate(ctx).Return(errors.New("an unexpected error has occurred while invalidation data"))

// Cache 2
cache2 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestChainClearWhenError(t *testing.T) {

// Cache 1
cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Clear(ctx).Return(errors.New("An unexpected error has occurred while invalidation data"))
cache1.EXPECT().Clear(ctx).Return(errors.New("an unexpected error has occurred while invalidation data"))

// Cache 2
cache2 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
Expand Down Expand Up @@ -435,7 +435,7 @@ func TestChainSetWhenErrorInChain(t *testing.T) {
ctx := context.Background()
key := "test-key"
value := "test-value"
interError := errors.New("An issue occurred with the cache")
interError := errors.New("an issue occurred with the cache")
store1.EXPECT().Set(ctx, key, value, nil).DoAndReturn(func(_, _, _, _ interface{}) error {
return interError
})
Expand All @@ -450,7 +450,7 @@ func TestChainSetWhenErrorInChain(t *testing.T) {
// When - Then
err := cache.Set(ctx, key, value, nil)

expErr := errors.New("error 1 of 1: Unable to set item into cache with store 'store1': An issue occurred with the cache")
expErr := errors.New("error 1 of 1: Unable to set item into cache with store 'store1': an issue occurred with the cache")
// Then
assert.Equal(t, expErr, err)
}
21 changes: 11 additions & 10 deletions cache/loadable_test.go
Expand Up @@ -3,13 +3,14 @@ package cache
import (
"context"
"errors"
"testing"
"time"

"github.com/eko/gocache/v3/store"
mocksCache "github.com/eko/gocache/v3/test/mocks/cache"
"github.com/golang/mock/gomock"
gocache "github.com/patrickmn/go-cache"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func TestNewLoadable(t *testing.T) {
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestLoadableGetWhenAlreadyInCache(t *testing.T) {
cache1.EXPECT().Get(ctx, "my-key").Return(cacheValue, nil)

loadFunc := func(_ context.Context, key any) (any, error) {
return nil, errors.New("Should not be called")
return nil, errors.New("should not be called")
}

cache := NewLoadable[any](loadFunc, cache1)
Expand All @@ -69,10 +70,10 @@ func TestLoadableGetWhenNotAvailableInLoadFunc(t *testing.T) {

// Cache
cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Get(ctx, "my-key").Return(nil, errors.New("Unable to find in cache 1"))
cache1.EXPECT().Get(ctx, "my-key").Return(nil, errors.New("unable to find in cache 1"))

loadFunc := func(_ context.Context, key any) (any, error) {
return nil, errors.New("An error has occurred while loading data from custom source")
return nil, errors.New("an error has occurred while loading data from custom source")
}

cache := NewLoadable[any](loadFunc, cache1)
Expand All @@ -82,7 +83,7 @@ func TestLoadableGetWhenNotAvailableInLoadFunc(t *testing.T) {

// Then
assert.Nil(t, value)
assert.Equal(t, errors.New("An error has occurred while loading data from custom source"), err)
assert.Equal(t, errors.New("an error has occurred while loading data from custom source"), err)
}

func TestLoadableGetWhenAvailableInLoadFunc(t *testing.T) {
Expand All @@ -99,7 +100,7 @@ func TestLoadableGetWhenAvailableInLoadFunc(t *testing.T) {

// Cache 1
cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Get(ctx, "my-key").Return(nil, errors.New("Unable to find in cache 1"))
cache1.EXPECT().Get(ctx, "my-key").Return(nil, errors.New("unable to find in cache 1"))
cache1.EXPECT().Set(ctx, "my-key", cacheValue).AnyTimes().Return(nil)

loadFunc := func(_ context.Context, key any) (any, error) {
Expand Down Expand Up @@ -149,7 +150,7 @@ func TestLoadableDeleteWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unable to delete key")
expectedErr := errors.New("unable to delete key")

cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Delete(ctx, "my-key").Return(expectedErr)
Expand Down Expand Up @@ -195,7 +196,7 @@ func TestLoadableInvalidateWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error when invalidating data")
expectedErr := errors.New("unexpected error when invalidating data")

cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Invalidate(ctx).Return(expectedErr)
Expand Down Expand Up @@ -241,7 +242,7 @@ func TestLoadableClearWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error when invalidating data")
expectedErr := errors.New("unexpected error when invalidating data")

cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Clear(ctx).Return(expectedErr)
Expand Down
6 changes: 3 additions & 3 deletions cache/metric_test.go
Expand Up @@ -151,7 +151,7 @@ func TestMetricDeleteWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unable to delete key")
expectedErr := errors.New("unable to delete key")

cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Delete(ctx, "my-key").Return(expectedErr)
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestMetricInvalidateWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error while invalidating data")
expectedErr := errors.New("unexpected error while invalidating data")

cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Invalidate(ctx).Return(expectedErr)
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestMetricClearWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error while clearing cache")
expectedErr := errors.New("unexpected error while clearing cache")

cache1 := mocksCache.NewMockSetterCacheInterface[any](ctrl)
cache1.EXPECT().Clear(ctx).Return(expectedErr)
Expand Down
12 changes: 6 additions & 6 deletions codec/codec_test.go
Expand Up @@ -104,7 +104,7 @@ func TestGetWithTTLWhenMiss(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unable to find in store")
expectedErr := errors.New("unable to find in store")

store := mocksStore.NewMockStoreInterface(ctrl)
store.EXPECT().GetWithTTL(ctx, "my-key").Return(nil, 0*time.Second, expectedErr)
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestGetWhenMiss(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unable to find in store")
expectedErr := errors.New("unable to find in store")

store := mocksStore.NewMockStoreInterface(ctrl)
store.EXPECT().Get(ctx, "my-key").Return(nil, expectedErr)
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestSetWhenError(t *testing.T) {
Hello: "world",
}

expectedErr := errors.New("Unable to set value in store")
expectedErr := errors.New("unable to set value in store")

mockedStore := mocksStore.NewMockStoreInterface(ctrl)
mockedStore.EXPECT().Set(ctx, "my-key", cacheValue, store.OptionsMatcher{
Expand Down Expand Up @@ -274,7 +274,7 @@ func TesDeleteWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unable to delete key")
expectedErr := errors.New("unable to delete key")

store := mocksStore.NewMockStoreInterface(ctrl)
store.EXPECT().Delete(ctx, "my-key").Return(expectedErr)
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestInvalidateWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error when invalidating data")
expectedErr := errors.New("unexpected error when invalidating data")

mockedStore := mocksStore.NewMockStoreInterface(ctrl)
mockedStore.EXPECT().Invalidate(ctx, store.InvalidateOptionsMatcher{
Expand Down Expand Up @@ -398,7 +398,7 @@ func TestClearWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error when clearing cache")
expectedErr := errors.New("unexpected error when clearing cache")

store := mocksStore.NewMockStoreInterface(ctrl)
store.EXPECT().Clear(ctx).Return(expectedErr)
Expand Down
10 changes: 5 additions & 5 deletions marshaler/marshaler_test.go
Expand Up @@ -112,7 +112,7 @@ func TestGetWhenNotFoundInStore(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unable to find item in store")
expectedErr := errors.New("unable to find item in store")

cache := mocksCache.NewMockCacheInterface[any](ctrl)
cache.EXPECT().Get(ctx, "my-key").Return(nil, expectedErr)
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestSetWhenError(t *testing.T) {

cacheValue := "test"

expectedErr := errors.New("An unexpected error occurred")
expectedErr := errors.New("an unexpected error occurred")

cache := mocksCache.NewMockCacheInterface[any](ctrl)
cache.EXPECT().Set(
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestDeleteWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unable to delete key")
expectedErr := errors.New("unable to delete key")

cache := mocksCache.NewMockCacheInterface[any](ctrl)
cache.EXPECT().Delete(ctx, "my-key").Return(expectedErr)
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestInvalidatingWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("Unexpected error when invalidating data")
expectedErr := errors.New("unexpected error when invalidating data")

cache := mocksCache.NewMockCacheInterface[any](ctrl)
cache.EXPECT().Invalidate(ctx, store.InvalidateOptionsMatcher{Tags: []string{"tag1"}}).Return(expectedErr)
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestClearWhenError(t *testing.T) {

ctx := context.Background()

expectedErr := errors.New("An unexpected error occurred")
expectedErr := errors.New("an unexpected error occurred")

cache := mocksCache.NewMockCacheInterface[any](ctrl)
cache.EXPECT().Clear(ctx).Return(expectedErr)
Expand Down
2 changes: 1 addition & 1 deletion store/bigcache.go
Expand Up @@ -44,7 +44,7 @@ func (s *BigcacheStore) Get(_ context.Context, key any) (any, error) {
return nil, err
}
if item == nil {
return nil, NotFoundWithCause(errors.New("Unable to retrieve data from bigcache"))
return nil, NotFoundWithCause(errors.New("unable to retrieve data from bigcache"))
}

return item, err
Expand Down

0 comments on commit 60d868f

Please sign in to comment.