TestFileCache_Persistence ensures data is loaded from disk when persisted.
(t *testing.T)
| 74 | |
| 75 | // TestFileCache_Persistence ensures data is loaded from disk when persisted. |
| 76 | func 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. |
| 105 | func resetCacheState() { |
nothing calls this directly
no test coverage detected