feat: add configurations for memory only, disk only, and memory & disk modes
All checks were successful
Release Tag / release (push) Successful in 14s

This commit is contained in:
2025-01-22 19:28:45 -06:00
parent ca069a20ee
commit 7401c040dc
8 changed files with 156 additions and 50 deletions

View File

@@ -20,7 +20,9 @@ func TestNew(t *testing.T) {
fast := testMemory()
slow := testMemory()
cache := New(fast, slow, nil)
cache := New(nil)
cache.SetFast(fast)
cache.SetSlow(slow)
if cache == nil {
t.Fatal("expected cache to be non-nil")
}
@@ -35,7 +37,9 @@ func TestNewPanics(t *testing.T) {
}
}()
New(nil, nil, nil)
cache := New(nil)
cache.SetFast(nil)
cache.SetSlow(nil)
}
func TestSetAndGet(t *testing.T) {
@@ -43,7 +47,9 @@ func TestSetAndGet(t *testing.T) {
fast := testMemory()
slow := testMemory()
cache := New(fast, slow, nil)
cache := New(nil)
cache.SetFast(fast)
cache.SetSlow(slow)
key := "test"
value := []byte("value")
@@ -66,7 +72,8 @@ func TestSetAndGetNoFast(t *testing.T) {
t.Parallel()
slow := testMemory()
cache := New(nil, slow, nil)
cache := New(nil)
cache.SetSlow(slow)
key := "test"
value := []byte("value")
@@ -89,9 +96,11 @@ func TestCaching(t *testing.T) {
fast := testMemory()
slow := testMemory()
cache := New(fast, slow, func(fi *vfs.FileInfo, cs cachestate.CacheState) bool {
cache := New(func(fi *vfs.FileInfo, cs cachestate.CacheState) bool {
return true
})
cache.SetFast(fast)
cache.SetSlow(slow)
key := "test"
value := []byte("value")
@@ -148,7 +157,9 @@ func TestGetNotFound(t *testing.T) {
fast := testMemory()
slow := testMemory()
cache := New(fast, slow, nil)
cache := New(nil)
cache.SetFast(fast)
cache.SetSlow(slow)
_, err := cache.Get("nonexistent")
if !errors.Is(err, vfserror.ErrNotFound) {
@@ -161,7 +172,9 @@ func TestDelete(t *testing.T) {
fast := testMemory()
slow := testMemory()
cache := New(fast, slow, nil)
cache := New(nil)
cache.SetFast(fast)
cache.SetSlow(slow)
key := "test"
value := []byte("value")
@@ -185,7 +198,9 @@ func TestStat(t *testing.T) {
fast := testMemory()
slow := testMemory()
cache := New(fast, slow, nil)
cache := New(nil)
cache.SetFast(fast)
cache.SetSlow(slow)
key := "test"
value := []byte("value")