check / check (push) Waiting to run
Service.Warm, the ImageCache interface, both GenerateSignedURL methods, signature.ParseParams, imagerequest.ParseImagePath, four symbols of internal/magic, the image processor's lists of supported formats, IsEmpty and Count of the allowlist, ssrfSafeDialer, CacheStale, ErrCacheMiss, ErrNegativeCache, ImageResponse.LastModified and the Load methods of ContentStorage and VariantStorage had no caller outside tests. They are gone, with the tests that tested only them. The handlers tests sign their image URLs with generateSignedURL, a test helper that builds the URL as the removed generator did. The SSRF dialer tests call dialSSRFSafe with no operator blocklist, which is all ssrfSafeDialer did. The tests of ParseImagePath and ContentStorage.Load call ParseImageURL and LoadWithSize instead. MIMEToImageFormat, ContentStorage.Store and CleanExpired stay, as pixa calls them. Model: opus-5-5
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package magic
|
|
|
|
import "testing"
|
|
|
|
// 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 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 != MIMETypeJXL {
|
|
t.Errorf("DetectFormat() = %q, %v, want %q", got, err, testMIMEJXL)
|
|
}
|
|
|
|
err = ValidateMagicBytes(tt.data, testMIMEJXL)
|
|
if err != nil {
|
|
t.Errorf("ValidateMagicBytes(%q) error = %v", testMIMEJXL, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestJPEGXLMIMEType verifies that image/jxl maps to the format jxl.
|
|
func TestJPEGXLMIMEType(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
format, ok := MIMEToImageFormat(testMIMEJXL)
|
|
if format != FormatJXL || !ok {
|
|
t.Errorf("MIMEToImageFormat(%q) = %q, %v, want %q, true",
|
|
testMIMEJXL, format, ok, FormatJXL)
|
|
}
|
|
}
|