From 3f8b2326e8f048ae92852f768fb1da0111867ff4 Mon Sep 17 00:00:00 2001 From: Leo Antunes Date: Tue, 26 Jul 2022 22:39:07 +0200 Subject: [PATCH] tests: be a bit more explicit on initialization cases --- cache.go | 3 ++- cache_test.go | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cache.go b/cache.go index 6230f9fd..9ab8e800 100644 --- a/cache.go +++ b/cache.go @@ -277,7 +277,8 @@ func (c *Cache) SetIfPresent(key, value interface{}, cost int64) bool { } func (c *Cache) setInternal(key, value interface{}, - cost int64, ttl time.Duration, onlyUpdate bool) bool { + cost int64, ttl time.Duration, onlyUpdate bool, +) bool { if c == nil || c.isClosed.Load() || key == nil { return false } diff --git a/cache_test.go b/cache_test.go index 04aea53f..c07d7e0a 100644 --- a/cache_test.go +++ b/cache_test.go @@ -120,20 +120,19 @@ func TestNewCache(t *testing.T) { _, err := NewCache(&Config{ NumCounters: 0, }) - require.Error(t, err) + require.Error(t, err, "instantiating without explicit Config.MaxCost should fail") _, err = NewCache(&Config{ NumCounters: 100, MaxCost: 0, }) - require.Error(t, err) + require.Error(t, err, "instantiating with Config.MaxCost == 0 should fail") _, err = NewCache(&Config{ - NumCounters: 100, - MaxCost: 10, - BufferItems: 0, + MaxCost: 10, }) - require.NoError(t, err) + require.NoError(t, err, "instantiating with Config.MaxCost != 0 should not fail") + require.NotNil(t, c) c, err := NewCache(&Config{ NumCounters: 100, @@ -141,7 +140,7 @@ func TestNewCache(t *testing.T) { BufferItems: 64, Metrics: true, }) - require.NoError(t, err) + require.NoError(t, err, "instantiating with all explicit values should not fail") require.NotNil(t, c) }