Files
opencloud/services/thumbnails/pkg/parity/errors_test.go
T
Dominik Schmidt 9b4e173020 test(thumbnails): compare the built-in generator against two real imagors
The same image goes to the built-in generator and to both imagor images,
and status, dimensions, format, frames and alpha are compared. A generator
that answers differently is held to that answer by a recorded override, so
the test fails once the divergence disappears. It runs once per resize
implementation, because make test builds the pure Go path while the images
ship vips.
2026-10-19 14:57:35 +02:00

51 lines
1.8 KiB
Go

package parity
// 406 instead of 400: imagor runs without an http loader here.
func errorsGroup() parityGroup {
return parityGroup{
name: "errors",
cases: []parityCase{
{
title: "an untyped upload part", path: "/unsafe/50x50/filters:format(png)/",
source: pngSource(300, 200), partType: "application/octet-stream",
want: "406",
},
{
title: "non-numeric dimensions", path: "/unsafe/axb/filters:format(png)/",
source: pngSource(300, 200), want: "400",
generatorOverrides: map[string]override{
"imagor": {answers: "200 300x200 png", because: "imagor ignores dimensions it cannot read"},
},
},
{
title: "an unknown operation", path: "/unsafe/shrink/50x50/filters:format(png)/",
source: pngSource(300, 200), want: "400",
generatorOverrides: map[string]override{
"imagor": {answers: "200 300x200 png", because: "imagor reads an unknown segment as a filename and returns the source"},
},
},
{
title: "bytes that are not an image", path: "/unsafe/50x50/filters:format(png)/",
source: source{name: "garbage", filename: "x.png", partType: "image/png", data: []byte("not an image")},
want: "406",
},
{
title: "a body that is not multipart", path: "/unsafe/50x50/filters:format(png)/",
source: pngSource(300, 200), rawBody: []byte("plain"), rawContentType: "text/plain",
want: "400",
generatorOverrides: map[string]override{
"imagor": {answers: "406", because: "no loader to fall back to"},
},
},
{
title: "a GET on a processing path", path: "/unsafe/50x50/filters:format(png)/",
source: pngSource(300, 200), method: "GET", rawContentType: "text/plain",
want: "405",
generatorOverrides: map[string]override{
"imagor": {answers: "200 non-image", because: "imagor serves an upload form there"},
},
},
},
}
}