tkcashgame_v4/pkg/cache/memcache/cache_internal_test.go

29 lines
420 B
Go

package memcache
import (
"context"
"testing"
"time"
)
func TestDeletedCache(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
nc := NewContext[string, int](ctx)
key := "key"
nc.Set(key, 1, WithExpiration(-time.Second))
_, ok := nc.cache.Get(key)
if !ok {
t.Fatal("want true")
}
nc.DeleteExpired()
_, ok = nc.cache.Get(key)
if ok {
t.Fatal("want false")
}
}