MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestFileCache_Persistence

Function TestFileCache_Persistence

internal/cache/cache_test.go:76–102  ·  view source on GitHub ↗

TestFileCache_Persistence ensures data is loaded from disk when persisted.

(t *testing.T)

Source from the content-addressed store, hash-verified

74
75// TestFileCache_Persistence ensures data is loaded from disk when persisted.
76func TestFileCache_Persistence(t *testing.T) {
77 dir := t.TempDir()
78
79 c1, err := NewFileCache(dir, true)
80 if err != nil {
81 t.Fatalf("create: %v", err)
82 }
83
84 _ = c1.Set("p", "val", time.Minute)
85
86 // Create new cache with same directory
87 c2, err := NewFileCache(dir, true)
88 if err != nil {
89 t.Fatalf("create2: %v", err)
90 }
91
92 var v string
93
94 found, err := c2.Get("p", &v)
95 if err != nil {
96 t.Fatalf("get: %v", err)
97 }
98
99 if !found || v != "val" {
100 t.Fatalf("expected persisted value, got %v found %v", v, found)
101 }
102}
103
104// resetCacheState resets package-level cache state for isolated testing.
105func resetCacheState() {

Callers

nothing calls this directly

Calls 3

SetMethod · 0.95
GetMethod · 0.95
NewFileCacheFunction · 0.85

Tested by

no test coverage detected