From 32f9166ececb172de873980e2be68c846c8cd38f Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 8 Jan 2026 13:11:12 -0800 Subject: [PATCH] Add failing test for AVIF encoding Test verifies that images can be encoded to AVIF format. Currently fails because AVIF encoding is not implemented. Removes the rejection test for AVIF output format. --- internal/imgcache/processor_test.go | 33 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/internal/imgcache/processor_test.go b/internal/imgcache/processor_test.go index 50fa026..c4a036b 100644 --- a/internal/imgcache/processor_test.go +++ b/internal/imgcache/processor_test.go @@ -3,7 +3,6 @@ package imgcache import ( "bytes" "context" - "errors" "image" "image/color" "image/jpeg" @@ -457,7 +456,7 @@ func TestImageProcessor_DecodeAVIF(t *testing.T) { } } -func TestImageProcessor_RejectsUnsupportedOutputFormat_AVIF(t *testing.T) { +func TestImageProcessor_EncodeAVIF(t *testing.T) { proc := NewImageProcessor() ctx := context.Background() @@ -470,12 +469,32 @@ func TestImageProcessor_RejectsUnsupportedOutputFormat_AVIF(t *testing.T) { FitMode: FitCover, } - _, err := proc.Process(ctx, bytes.NewReader(input), req) - if err == nil { - t.Fatal("Process() should return error for unsupported AVIF encoding") + result, err := proc.Process(ctx, bytes.NewReader(input), req) + if err != nil { + t.Fatalf("Process() error = %v, want nil (AVIF encoding should work)", err) + } + defer result.Content.Close() + + // Verify output is valid AVIF + 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 != MIMETypeAVIF { + t.Errorf("Output format = %v, want %v", mime, MIMETypeAVIF) + } + + // 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) } }