From 51a1ae4a133c210a47407fbe67588c76aceca1a9 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 8 Jan 2026 12:25:01 -0800 Subject: [PATCH] Add failing test for hot cache ContentType Hot cache lookups must return ContentType to serve correct Content-Type headers. Currently returns empty string. --- internal/imgcache/cache_test.go | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/internal/imgcache/cache_test.go b/internal/imgcache/cache_test.go index 9319797..388ff2e 100644 --- a/internal/imgcache/cache_test.go +++ b/internal/imgcache/cache_test.go @@ -327,6 +327,60 @@ func TestCache_HotCache(t *testing.T) { } } +func TestCache_HotCache_ReturnsContentType(t *testing.T) { + cache, _ := setupTestCache(t) + ctx := context.Background() + + req := &ImageRequest{ + SourceHost: "cdn.example.com", + SourcePath: "/photos/hotct.jpg", + Size: Size{Width: 800, Height: 600}, + Format: FormatWebP, + Quality: 85, + FitMode: FitCover, + } + + // Store content + sourceContent := []byte("source data") + fetchResult := &FetchResult{ + ContentType: "image/jpeg", + Headers: map[string][]string{}, + } + + _, err := cache.StoreSource(ctx, req, bytes.NewReader(sourceContent), fetchResult) + if err != nil { + t.Fatalf("StoreSource() error = %v", err) + } + + metaID, _ := cache.GetSourceMetadataID(ctx, req) + + outputContent := []byte("output webp data") + _, err = cache.StoreOutput(ctx, req, metaID, bytes.NewReader(outputContent), "image/webp") + if err != nil { + t.Fatalf("StoreOutput() error = %v", err) + } + + // First lookup populates hot cache + result1, err := cache.Lookup(ctx, req) + if err != nil { + t.Fatalf("Lookup() first error = %v", err) + } + + if result1.ContentType != "image/webp" { + t.Errorf("Lookup() first ContentType = %q, want %q", result1.ContentType, "image/webp") + } + + // Second lookup uses hot cache - must still have ContentType + result2, err := cache.Lookup(ctx, req) + if err != nil { + t.Fatalf("Lookup() second error = %v", err) + } + + if result2.ContentType != "image/webp" { + t.Errorf("Lookup() hot cache ContentType = %q, want %q", result2.ContentType, "image/webp") + } +} + func TestCache_GetOutput(t *testing.T) { cache, _ := setupTestCache(t) ctx := context.Background()