From 0c9eb35bd2a321f8165f9f96089bf7666e46f0f2 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 8 Jan 2026 11:54:03 -0800 Subject: [PATCH] Add failing test for WebP encoding support TDD: This test expects WebP encoding to succeed. It currently fails because WebP encoding is not implemented (returns ErrUnsupportedOutputFormat). The test will pass once we add the gen2brain/webp library. --- internal/imgcache/processor_test.go | 34 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/internal/imgcache/processor_test.go b/internal/imgcache/processor_test.go index 4a23d47..b0b6135 100644 --- a/internal/imgcache/processor_test.go +++ b/internal/imgcache/processor_test.go @@ -313,7 +313,7 @@ func TestImageProcessor_AcceptsMaxDimensionInput(t *testing.T) { defer result.Content.Close() } -func TestImageProcessor_RejectsUnsupportedOutputFormat_WebP(t *testing.T) { +func TestImageProcessor_EncodeWebP(t *testing.T) { proc := NewImageProcessor() ctx := context.Background() @@ -322,17 +322,37 @@ func TestImageProcessor_RejectsUnsupportedOutputFormat_WebP(t *testing.T) { req := &ImageRequest{ Size: Size{Width: 100, Height: 75}, Format: FormatWebP, - Quality: 85, + Quality: 80, FitMode: FitCover, } - _, err := proc.Process(ctx, bytes.NewReader(input), req) - if err == nil { - t.Fatal("Process() should return error for unsupported WebP encoding") + result, err := proc.Process(ctx, bytes.NewReader(input), req) + if err != nil { + t.Fatalf("Process() error = %v, want nil", err) + } + defer result.Content.Close() + + // Verify output is valid WebP + data, err := io.ReadAll(result.Content) + if err != nil { + t.Fatalf("failed to read result: %v", err) } - if !errors.Is(err, ErrUnsupportedOutputFormat) { - t.Errorf("Process() error = %v, want ErrUnsupportedOutputFormat", err) + mime, err := DetectFormat(data) + if err != nil { + t.Fatalf("DetectFormat() error = %v", err) + } + + if mime != MIMETypeWebP { + t.Errorf("Output format = %v, want %v", mime, MIMETypeWebP) + } + + // Verify dimensions + if result.Width != 100 { + t.Errorf("Width = %d, want 100", result.Width) + } + if result.Height != 75 { + t.Errorf("Height = %d, want 75", result.Height) } }