From 817d760b4dccdae00cbae2283a1d1131fe2bbefe Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 8 Jan 2026 12:20:19 -0800 Subject: [PATCH] Add failing tests for proportional scaling When only one dimension is provided (e.g., width=400, height=0), the image should scale proportionally. Currently returns 0x0. --- internal/imgcache/processor_test.go | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/internal/imgcache/processor_test.go b/internal/imgcache/processor_test.go index b0b6135..209b141 100644 --- a/internal/imgcache/processor_test.go +++ b/internal/imgcache/processor_test.go @@ -196,6 +196,66 @@ func TestImageProcessor_FitContain(t *testing.T) { } } +func TestImageProcessor_ProportionalScale_WidthOnly(t *testing.T) { + proc := NewImageProcessor() + ctx := context.Background() + + // 800x600 image, request width=400 height=0 + // Should scale proportionally to 400x300 + input := createTestJPEG(t, 800, 600) + + req := &ImageRequest{ + Size: Size{Width: 400, Height: 0}, + Format: FormatJPEG, + Quality: 85, + FitMode: FitCover, + } + + result, err := proc.Process(ctx, bytes.NewReader(input), req) + if err != nil { + t.Fatalf("Process() error = %v", err) + } + defer result.Content.Close() + + if result.Width != 400 { + t.Errorf("Process() width = %d, want 400", result.Width) + } + + if result.Height != 300 { + t.Errorf("Process() height = %d, want 300", result.Height) + } +} + +func TestImageProcessor_ProportionalScale_HeightOnly(t *testing.T) { + proc := NewImageProcessor() + ctx := context.Background() + + // 800x600 image, request width=0 height=300 + // Should scale proportionally to 400x300 + input := createTestJPEG(t, 800, 600) + + req := &ImageRequest{ + Size: Size{Width: 0, Height: 300}, + Format: FormatJPEG, + Quality: 85, + FitMode: FitCover, + } + + result, err := proc.Process(ctx, bytes.NewReader(input), req) + if err != nil { + t.Fatalf("Process() error = %v", err) + } + defer result.Content.Close() + + if result.Width != 400 { + t.Errorf("Process() width = %d, want 400", result.Width) + } + + if result.Height != 300 { + t.Errorf("Process() height = %d, want 300", result.Height) + } +} + func TestImageProcessor_ProcessPNG(t *testing.T) { proc := NewImageProcessor() ctx := context.Background()