package ttl import ( "testing" "time" "forge.cadoles.com/cadoles/bouncer/internal/cache/memory" ) func TestCache(t *testing.T) { cache := NewCache( memory.NewCache[string, int](), memory.NewCache[string, time.Time](), time.Second, ) key := "foo" if _, exists := cache.Get(key); exists { t.Errorf("cache.Get(\"%s\"): should not exists", key) } cache.Set(key, 1) value, exists := cache.Get(key) if !exists { t.Errorf("cache.Get(\"%s\"): should exists", key) } if e, g := 1, value; e != g { t.Errorf("cache.Get(\"%s\"): expected '%v', got '%v'", key, e, g) } time.Sleep(time.Second) if _, exists := cache.Get("foo"); exists { t.Errorf("cache.Get(\"%s\"): should not exists", key) } }