Add testable examples

This commit is contained in:
Dan Jones 2025-04-21 14:32:12 -05:00
commit 6dc48772c0
2 changed files with 34 additions and 1 deletions

View file

@ -1,3 +1,4 @@
//nolint:perfsprint // Not that concerned about microoptimizations for test code
package ezcache_test
import (
@ -69,7 +70,7 @@ func TestGetExpire(t *testing.T) {
assert.True(t, hit)
hit = false
time.Sleep(2)
time.Sleep(2 * time.Nanosecond)
val, err = cache.Get(4)
assert.NoError(t, err)
assert.Equal(t, "4", val)
@ -77,6 +78,7 @@ func TestGetExpire(t *testing.T) {
}
func TestGetError(t *testing.T) {
//nolint:err113 // It's just a test for an error.
cache, _ := ezcache.New(func(k uint8) (byte, error) { return 0, fmt.Errorf("Nope for %d", k) }, 1)
_, err := cache.Get(4)