chore: merge backend repo history into monorepo at backend/

git-subtree-dir: backend
git-subtree-mainline: dc11190527
git-subtree-split: acae976622
This commit is contained in:
2026-09-27 10:30:16 +03:30
67 changed files with 6835 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
package cache
import (
"testing"
"time"
)
func TestTTLCache_SetGet(t *testing.T) {
c := New[string, int](time.Minute)
c.Set("a", 42)
v, ok := c.Get("a")
if !ok || v != 42 {
t.Fatalf("expected (42, true), got (%d, %v)", v, ok)
}
}
func TestTTLCache_MissingKey(t *testing.T) {
c := New[string, int](time.Minute)
if _, ok := c.Get("missing"); ok {
t.Fatal("expected miss for key that was never set")
}
}
func TestTTLCache_Expiry(t *testing.T) {
c := New[string, int](10 * time.Millisecond)
c.Set("a", 1)
if _, ok := c.Get("a"); !ok {
t.Fatal("expected hit immediately after Set")
}
time.Sleep(30 * time.Millisecond)
if _, ok := c.Get("a"); ok {
t.Fatal("expected miss after TTL expired")
}
}
func TestTTLCache_Delete(t *testing.T) {
c := New[string, int](time.Minute)
c.Set("a", 1)
c.Delete("a")
if _, ok := c.Get("a"); ok {
t.Fatal("expected miss after Delete")
}
}
func TestTTLCache_Clear(t *testing.T) {
c := New[string, int](time.Minute)
c.Set("a", 1)
c.Set("b", 2)
c.Clear()
if _, ok := c.Get("a"); ok {
t.Fatal("expected miss for 'a' after Clear")
}
if _, ok := c.Get("b"); ok {
t.Fatal("expected miss for 'b' after Clear")
}
}