From 900591299f5a8ef61a09722205dfab03cc6ecae5 Mon Sep 17 00:00:00 2001 From: Sanghee Choi <32831939+pengin7384@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:27:40 +0900 Subject: [PATCH] common/lru: add test case for BasicLRU.Peek (#27559) --- common/lru/basiclru_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/lru/basiclru_test.go b/common/lru/basiclru_test.go index e2d3559f5..29812bda1 100644 --- a/common/lru/basiclru_test.go +++ b/common/lru/basiclru_test.go @@ -170,6 +170,20 @@ func TestBasicLRUContains(t *testing.T) { } } +// Test that Peek doesn't update recent-ness +func TestBasicLRUPeek(t *testing.T) { + cache := NewBasicLRU[int, int](2) + cache.Add(1, 1) + cache.Add(2, 2) + if v, ok := cache.Peek(1); !ok || v != 1 { + t.Errorf("1 should be set to 1") + } + cache.Add(3, 3) + if cache.Contains(1) { + t.Errorf("should not have updated recent-ness of 1") + } +} + func BenchmarkLRU(b *testing.B) { var ( capacity = 1000