Skip to content

Commit

Permalink
Add tests to prove/enforce 0-value byte slice caching (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshufro authored and janisz committed Mar 27, 2018
1 parent d26c0aa commit f31987a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bigcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,43 @@ func TestHashCollision(t *testing.T) {
assert.Equal(t, cache.Stats().Collisions, int64(1))
}

func TestNilValueCaching(t *testing.T) {
t.Parallel()

// given
cache, _ := NewBigCache(Config{
Shards: 1,
LifeWindow: 5 * time.Second,
MaxEntriesInWindow: 1,
MaxEntrySize: 1,
HardMaxCacheSize: 1,
})

// when
cache.Set("Kierkegaard", []byte{})
cachedValue, err := cache.Get("Kierkegaard")

// then
assert.NoError(t, err)
assert.Equal(t, []byte{}, cachedValue)

// when
cache.Set("Sartre", nil)
cachedValue, err = cache.Get("Sartre")

// then
assert.NoError(t, err)
assert.Equal(t, []byte{}, cachedValue)

// when
cache.Set("Nietzsche", []byte(nil))
cachedValue, err = cache.Get("Nietzsche")

// then
assert.NoError(t, err)
assert.Equal(t, []byte{}, cachedValue)
}

type mockedLogger struct {
lastFormat string
lastArgs []interface{}
Expand Down

0 comments on commit f31987a

Please sign in to comment.