(t *testing.T)
| 351 | } |
| 352 | |
| 353 | func TestCacheFinalize(t *testing.T) { |
| 354 | c := New() |
| 355 | numCalled := 0 |
| 356 | c.SetFinalizer(func(v any) { |
| 357 | numCalled++ |
| 358 | }) |
| 359 | create := func(path string) (any, bool, error) { |
| 360 | return path, true, nil |
| 361 | } |
| 362 | _, _ = c.Get("ok", create) |
| 363 | assert.Equal(t, 0, numCalled) |
| 364 | c.Clear() |
| 365 | assert.Equal(t, 1, numCalled) |
| 366 | |
| 367 | _, _ = c.Get("ok", create) |
| 368 | c.Delete("ok") |
| 369 | assert.Equal(t, 2, numCalled) |
| 370 | |
| 371 | _, _ = c.Get("ok", create) |
| 372 | c.DeletePrefix("ok") |
| 373 | assert.Equal(t, 3, numCalled) |
| 374 | |
| 375 | _, _ = c.Get("old", create) |
| 376 | _, _ = c.Get("new", create) |
| 377 | c.Rename("old", "new") |
| 378 | assert.Equal(t, 4, numCalled) |
| 379 | |
| 380 | c.expireDuration = 1 * time.Millisecond |
| 381 | _, _ = c.Get("ok", create) |
| 382 | time.Sleep(2 * time.Millisecond) |
| 383 | c.cacheExpire() // "ok" and "new" fall out of cache |
| 384 | assert.Equal(t, 6, numCalled) |
| 385 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…