Add tests for unsupported output format errors

Tests verify that WebP and AVIF encoding requests return
ErrUnsupportedOutputFormat instead of silently falling back
to a different format.
This commit is contained in:
2026-01-08 11:08:16 -08:00
parent 014c144d73
commit df6d347e68

View File

@@ -3,6 +3,7 @@ package imgcache
import (
"bytes"
"context"
"errors"
"image"
"image/color"
"image/jpeg"
@@ -311,3 +312,49 @@ func TestImageProcessor_AcceptsMaxDimensionInput(t *testing.T) {
}
defer result.Content.Close()
}
func TestImageProcessor_RejectsUnsupportedOutputFormat_WebP(t *testing.T) {
proc := NewImageProcessor()
ctx := context.Background()
input := createTestJPEG(t, 200, 150)
req := &ImageRequest{
Size: Size{Width: 100, Height: 75},
Format: FormatWebP,
Quality: 85,
FitMode: FitCover,
}
_, err := proc.Process(ctx, bytes.NewReader(input), req)
if err == nil {
t.Fatal("Process() should return error for unsupported WebP encoding")
}
if !errors.Is(err, ErrUnsupportedOutputFormat) {
t.Errorf("Process() error = %v, want ErrUnsupportedOutputFormat", err)
}
}
func TestImageProcessor_RejectsUnsupportedOutputFormat_AVIF(t *testing.T) {
proc := NewImageProcessor()
ctx := context.Background()
input := createTestJPEG(t, 200, 150)
req := &ImageRequest{
Size: Size{Width: 100, Height: 75},
Format: FormatAVIF,
Quality: 85,
FitMode: FitCover,
}
_, err := proc.Process(ctx, bytes.NewReader(input), req)
if err == nil {
t.Fatal("Process() should return error for unsupported AVIF encoding")
}
if !errors.Is(err, ErrUnsupportedOutputFormat) {
t.Errorf("Process() error = %v, want ErrUnsupportedOutputFormat", err)
}
}