package imageprocessor import ( "bytes" "errors" "testing" ) // TestImageProcessor_RefusesComputedSideAboveMaximum verifies that a size // with one side 0, which Process computes from the input's proportions, is // served when that side comes out at MaxOutputDimension and refused with // ErrOutputTooLarge when it would be above. A 4096x1 or 1x4096 input given // 2 for its short side has 8192 for its long side. func TestImageProcessor_RefusesComputedSideAboveMaximum(t *testing.T) { t.Parallel() tests := []struct { name string inputWidth, inputHeight int size Size wantErr error }{ {"width at the maximum", 4096, 1, Size{Height: 2}, nil}, {"width above the maximum", 4096, 1, Size{Height: 3}, ErrOutputTooLarge}, {"height at the maximum", 1, 4096, Size{Width: 2}, nil}, {"height above the maximum", 1, 4096, Size{Width: 3}, ErrOutputTooLarge}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() input := createTestJPEG(t, tt.inputWidth, tt.inputHeight) result, err := New(Params{}).Process(t.Context(), bytes.NewReader(input), &Request{Size: tt.size, Format: FormatJPEG, FitMode: FitCover}) if result != nil { t.Logf("Process() made %dx%d", result.Width, result.Height) if max(result.Width, result.Height) != MaxOutputDimension { t.Errorf("Process() made %dx%d, want a side of %d", result.Width, result.Height, MaxOutputDimension) } } if !errors.Is(err, tt.wantErr) { t.Errorf("Process() error = %v, want %v", err, tt.wantErr) } }) } }