check / check (push) Canceled after 0s
magic.DetectFormat returns an imagerequest.Format. ValidateMagicBytes returns the format it checked against the upstream Content-Type. The cache reads a cached source's format from its file's first bytes, as it reads a variant's. The proxy hands the format to Process. Process refuses a format that is not a source format, and input libvips would load with another loader, such as an SVG passing as AVIF. Format.MIMEType declares each MIME string once, and the fetcher, the cache's variant read and the Accept matching use it. magic.MIMEType, magic.ImageFormat, MIMEToImageFormat, magic's SVG detection, detectFormat, formatFromString, FormatToMIME and Result.InputFormat are gone. Model: opus-5-5
45 lines
1019 B
Go
45 lines
1019 B
Go
package magic
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"sneak.berlin/go/pixa/internal/imagerequest"
|
|
)
|
|
|
|
// testMIMEJXL is the MIME type of JPEG XL.
|
|
const testMIMEJXL = "image/jxl"
|
|
|
|
// TestDetectFormatJPEGXL verifies that both JPEG XL signatures, that of a
|
|
// bare codestream and that of the container, are detected as JPEG XL and
|
|
// match the MIME type image/jxl.
|
|
func TestDetectFormatJPEGXL(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
data []byte
|
|
}{
|
|
{"codestream", pad(0xFF, 0x0A)},
|
|
{"container", pad(
|
|
0x00, 0x00, 0x00, 0x0C, 0x4A, 0x58, 0x4C, 0x20, 0x0D, 0x0A, 0x87, 0x0A,
|
|
)},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got, err := DetectFormat(tt.data)
|
|
if err != nil || got != imagerequest.FormatJXL {
|
|
t.Errorf("DetectFormat() = %q, %v, want %q",
|
|
got, err, imagerequest.FormatJXL)
|
|
}
|
|
|
|
_, err = ValidateMagicBytes(tt.data, testMIMEJXL)
|
|
if err != nil {
|
|
t.Errorf("ValidateMagicBytes(%q) error = %v", testMIMEJXL, err)
|
|
}
|
|
})
|
|
}
|
|
}
|