ussd/internal/storage/timed_test.go

36 lines
667 B
Go
Raw Normal View History

2024-10-02 23:06:43 +02:00
package storage
import (
"context"
"testing"
"time"
"git.defalsify.org/vise.git/db"
memdb "git.defalsify.org/vise.git/db/mem"
)
func TestStaleDb(t *testing.T) {
ctx := context.Background()
mdb := memdb.NewMemDb()
err := mdb.Connect(ctx, "")
if err != nil {
t.Fatal(err)
}
tdb := NewTimedDb(mdb, time.Duration(time.Millisecond))
tdb.SetPrefix(db.DATATYPE_USERDATA)
k := []byte("foo")
err = tdb.Put(ctx, k, []byte("bar"))
if err != nil {
t.Fatal(err)
}
if tdb.Stale(ctx, db.DATATYPE_USERDATA, k) {
t.Fatal("expected not stale")
}
time.Sleep(time.Millisecond)
if !tdb.Stale(ctx, db.DATATYPE_USERDATA, k) {
t.Fatal("expected stale")
}
}