✨ It works!
This commit is contained in:
parent
40ed936c47
commit
3367cce0df
2 changed files with 73 additions and 9 deletions
|
|
@ -42,3 +42,43 @@ func TestNewBadExpiry(tt *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHappy(t *testing.T) {
|
||||
var hit bool
|
||||
cache, _ := ezcache.New(func(key uint8) (string, error) { hit = true; return fetcher(key) }, 5*time.Second)
|
||||
|
||||
val, err := cache.Get(4)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "4", val)
|
||||
assert.True(t, hit)
|
||||
|
||||
hit = false
|
||||
val, err = cache.Get(4)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "4", val)
|
||||
assert.False(t, hit)
|
||||
}
|
||||
|
||||
func TestGetExpire(t *testing.T) {
|
||||
var hit bool
|
||||
cache, _ := ezcache.New(func(key uint8) (string, error) { hit = true; return fetcher(key) }, 1)
|
||||
|
||||
val, err := cache.Get(4)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "4", val)
|
||||
assert.True(t, hit)
|
||||
|
||||
hit = false
|
||||
time.Sleep(2)
|
||||
val, err = cache.Get(4)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "4", val)
|
||||
assert.True(t, hit)
|
||||
}
|
||||
|
||||
func TestGetError(t *testing.T) {
|
||||
cache, _ := ezcache.New(func(k uint8) (byte, error) { return 0, fmt.Errorf("Nope for %d", k) }, 1)
|
||||
|
||||
_, err := cache.Get(4)
|
||||
assert.ErrorContains(t, err, "Nope for 4")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue