Add failing test for hot cache ContentType
Hot cache lookups must return ContentType to serve correct Content-Type headers. Currently returns empty string.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user