TestFileCache_SetGet tests basic set and get operations for FileCache.
(t *testing.T)
| 10 | |
| 11 | // TestFileCache_SetGet tests basic set and get operations for FileCache. |
| 12 | func 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. |
| 51 | func TestFileCache_TTL(t *testing.T) { |
nothing calls this directly
no test coverage detected