// +build memory package memory import ( "testing" "time" "github.com/gofiber/utils" ) func Test_Memory_Config(t *testing.T) { t.Parallel() store := New(Config{}) utils.AssertEqual(t, ConfigDefault.GCInterval, store.gcInterval) } func Test_Memory_Set(t *testing.T) { t.Parallel() store := New() id := "hello" value := []byte("Hi there!") err := store.Set(id, value, 0) utils.AssertEqual(t, nil, err) utils.AssertEqual(t, entry{value, 0}, store.db[id]) } func Test_Memory_SetExpiry(t *testing.T) { t.Parallel() store := New() id := "hello" value := []byte("Hi there!") expiry := time.Second * 10 err := store.Set(id, value, expiry) utils.AssertEqual(t, nil, err) now := time.Now().Unix() fromStore, found := store.db[id] utils.AssertEqual(t, true, found) delta := fromStore.expiry - now upperBound := int64(expiry.Seconds()) lowerBound := upperBound - 2 if !(delta <= upperBound && delta > lowerBound) { t.Fatalf("Test_SetExpiry: expiry delta out of bounds (is %d, must be %d