diff --git a/internal/imgcache/negative_cache_internal_test.go b/internal/imgcache/negative_cache_internal_test.go index e9b5f8a..ffb6079 100644 --- a/internal/imgcache/negative_cache_internal_test.go +++ b/internal/imgcache/negative_cache_internal_test.go @@ -97,8 +97,9 @@ func TestNegativeCache_Expired(t *testing.T) { // TestService_Get_ServesCachedVariantOfNegativeCachedURL caches a variant of // the test photo, then keeps a failed fetch of the photo's URL in the negative // cache, as a failed fetch for another variant does once the source has been -// evicted. The cached variant is still served; a variant not in the cache is -// still refused. +// evicted. The cached variant is still served, and a variant not in the cache +// is made from the cached source. Once the source is evicted, a variant not in +// the cache needs a fetch and is refused. func TestService_Get_ServesCachedVariantOfNegativeCachedURL(t *testing.T) { t.Parallel() @@ -129,11 +130,31 @@ func TestService_Get_ServesCachedVariantOfNegativeCachedURL(t *testing.T) { resp.CacheStatus, CacheHit) } - _, err = svc.Get(t.Context(), photoVariant(fixtures, 40, FitCover)) - t.Logf("Get() of a variant not in the cache: error = %v", err) + resp, err = svc.Get(t.Context(), photoVariant(fixtures, 40, FitCover)) + t.Logf("Get() of a variant made from the cached source: error = %v", err) + + if err != nil { + t.Fatalf("Get() of a variant made from the cached source error = %v", err) + } + + _ = resp.Content.Close() + + contentHash, _, err := svc.cache.LookupSource(t.Context(), + photoVariant(fixtures, 85, FitCover)) + if err != nil || contentHash == "" { + t.Fatalf("LookupSource() = %q, %v, want the cached source", contentHash, err) + } + + err = svc.cache.evictSourceBlob(t.Context(), contentHash) + if err != nil { + t.Fatalf("evictSourceBlob() error = %v", err) + } + + _, err = svc.Get(t.Context(), photoVariant(fixtures, 60, FitCover)) + t.Logf("Get() of a variant whose source was evicted: error = %v", err) if !errors.Is(err, ErrNegativeCached) { - t.Errorf("Get() of a variant not in the cache error = %v, want %v", + t.Errorf("Get() of a variant whose source was evicted error = %v, want %v", err, ErrNegativeCached) } }