check / check (push) Canceled after 0s
The new package internal/imagerequest holds the request type, its two parts Source and Transform, the Format and Fit types, the dimension and fit checks, the /v1/image/ path parsing and the variant key; it imports no other package of pixa. imgcache.ParsedURL, imgcache.ImageRequest, signature.Request, imageprocessor.Request, the second Size, format and fit types and the conversions between them are gone. The image processor takes a Transform only. encurl keeps a private struct with the token's short CBOR field names. VariantKey moves with the function that makes it. Tests follow the moved and renamed code; the tests of the removed conversions go with them. Model: opus-5-5
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
package imagerequest
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateImageRequest(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
req Request
|
|
wantErr error
|
|
}{
|
|
{
|
|
name: "within bounds",
|
|
req: Request{Transform: Transform{
|
|
Size: Size{Width: 800, Height: 600}, FitMode: FitCover,
|
|
}},
|
|
},
|
|
{
|
|
name: "original size and empty fit",
|
|
req: Request{Transform: Transform{Size: Size{Width: 0, Height: 0}}},
|
|
},
|
|
{
|
|
name: "width over limit",
|
|
req: Request{Transform: Transform{
|
|
Size: Size{Width: MaxDimension + 1, Height: 600},
|
|
}},
|
|
wantErr: ErrDimensionTooLarge,
|
|
},
|
|
{
|
|
name: "height over limit",
|
|
req: Request{Transform: Transform{
|
|
Size: Size{Width: 800, Height: MaxDimension + 1},
|
|
}},
|
|
wantErr: ErrDimensionTooLarge,
|
|
},
|
|
{
|
|
name: "negative width",
|
|
req: Request{Transform: Transform{Size: Size{Width: -1, Height: 600}}},
|
|
wantErr: ErrInvalidSize,
|
|
},
|
|
{
|
|
name: "invalid fit mode",
|
|
req: Request{Transform: Transform{
|
|
Size: Size{Width: 800, Height: 600}, FitMode: "bogus",
|
|
}},
|
|
wantErr: ErrInvalidFitMode,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := ValidateImageRequest(&tt.req)
|
|
if tt.wantErr == nil {
|
|
if err != nil {
|
|
t.Fatalf("ValidateImageRequest() error = %v, want nil", err)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
if !errors.Is(err, tt.wantErr) {
|
|
t.Fatalf("ValidateImageRequest() error = %v, want %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|