Skip to content

Commit

Permalink
tests: be a bit more explicit on initialization cases
Browse files Browse the repository at this point in the history
  • Loading branch information
costela committed Jul 26, 2022
1 parent ff56594 commit 3f8b232
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 6 additions & 7 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,27 @@ 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,
MaxCost: 10,
BufferItems: 64,
Metrics: true,
})
require.NoError(t, err)
require.NoError(t, err, "instantiating with all explicit values should not fail")
require.NotNil(t, c)
}

Expand Down

0 comments on commit 3f8b232

Please sign in to comment.