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

Function TestFileCache_SetGet

internal/cache/cache_test.go:12–48  ·  view source on GitHub ↗

TestFileCache_SetGet tests basic set and get operations for FileCache.

(t *testing.T)

Source from the content-addressed store, hash-verified

10
11// TestFileCache_SetGet tests basic set and get operations for FileCache.
12func TestFileCache_SetGet(t *testing.T) {
13 dir := t.TempDir()
14
15 c, err := NewFileCache(dir, true)
16 if err != nil {
17 t.Fatalf("failed to create cache: %v", err)
18 }
19
20 type data struct{ Name string }
21
22 key := "test-key"
23 expected := data{Name: "value"}
24
25 if setErr := c.Set(key, expected, time.Minute); setErr != nil {
26 t.Fatalf("set error: %v", setErr)
27 }
28
29 var got data
30
31 found, err := c.Get(key, &got)
32 if err != nil {
33 t.Fatalf("get error: %v", err)
34 }
35
36 if !found {
37 t.Fatalf("expected item not found")
38 }
39
40 if got != expected {
41 t.Fatalf("expected %v got %v", expected, got)
42 }
43
44 // Ensure file exists for persistence
45 if _, err := os.Stat(filepath.Join(dir, key+".json")); err != nil {
46 t.Fatalf("expected cache file: %v", err)
47 }
48}
49
50// TestFileCache_TTL verifies that expired items are not returned.
51func TestFileCache_TTL(t *testing.T) {

Callers

nothing calls this directly

Calls 3

SetMethod · 0.95
GetMethod · 0.95
NewFileCacheFunction · 0.85

Tested by

no test coverage detected