From 2a574d6f3b832c332295e9c733b227d8f1ec58e0 Mon Sep 17 00:00:00 2001 From: Adora Laura Kalb Date: Fri, 19 Apr 2024 11:10:00 +0200 Subject: [PATCH] add test for cache miss --- cache/cache_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cache/cache_test.go b/cache/cache_test.go index 38be9a9..254b5d3 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -32,3 +32,18 @@ func TestCacheGet(t *testing.T) { t.Fatalf("cache.Get(\"1.2.3.4\") = %f, want %f", score.Score, testFloat) } } + +func TestCacheMiss(t *testing.T) { + now := time.Now() + const testFloat = 1.23456 + + expiredTime := now.Add(-(time.Minute * 10)) + + cache := NewLocalCache() + cache.Add(testFloat, netip.MustParseAddr("1.2.3.4"), expiredTime) + + _, err := cache.Get(netip.MustParseAddr("1.2.3.4")) + if err == nil { + t.Fatalf("cache.Get(\"1.2.3.4\") = got nil, want error") + } +}