mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
test(icon): add test case to verify SVG minification with error
This commit is contained in:
parent
cad40cc158
commit
1b1ceaf8b4
1 changed files with 24 additions and 3 deletions
|
@ -194,16 +194,37 @@ func TestResizeInvalidImage(t *testing.T) {
|
||||||
t.Fatalf("Tried to convert an invalid image")
|
t.Fatalf("Tried to convert an invalid image")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMinifySvg(t *testing.T) {
|
func TestMinifySvg(t *testing.T) {
|
||||||
data := []byte(`<svg path d=" M1 4h-.001 V1h2v.001 M1 2.6 h1v.001"/></svg>`)
|
data := []byte(`<svg path d=" M1 4h-.001 V1h2v.001 M1 2.6 h1v.001"/></svg>`)
|
||||||
want := []byte(`<svg path="" d="M1 4H.999V1h2v.001M1 2.6h1v.001"/></svg>`)
|
want := []byte(`<svg path="" d="M1 4H.999V1h2v.001M1 2.6h1v.001"/></svg>`)
|
||||||
|
icon := model.Icon{Content: data, MimeType: "image/svg+xml"}
|
||||||
|
got := resizeIcon(&icon).Content
|
||||||
|
if !bytes.Equal(want, got) {
|
||||||
|
t.Fatalf("Didn't correctly minify the svg: got %s instead of %s", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinifySvgWithError(t *testing.T) {
|
||||||
|
// Invalid SVG with malformed XML that should cause minification to fail
|
||||||
|
data := []byte(`<svg><><invalid-tag<>unclosed`)
|
||||||
|
original := make([]byte, len(data))
|
||||||
|
copy(original, data)
|
||||||
|
|
||||||
icon := model.Icon{
|
icon := model.Icon{
|
||||||
Content: data,
|
Content: data,
|
||||||
MimeType: "image/svg+xml",
|
MimeType: "image/svg+xml",
|
||||||
}
|
}
|
||||||
got := resizeIcon(&icon).Content
|
|
||||||
if !bytes.Equal(want, got) {
|
result := resizeIcon(&icon)
|
||||||
t.Fatalf("Didn't correctly minimize the svg: got %s instead of %s", got, want)
|
|
||||||
|
// When minification fails, the original content should be preserved
|
||||||
|
if !bytes.Equal(original, result.Content) {
|
||||||
|
t.Fatalf("Expected original content to be preserved on minification error, got %s instead of %s", result.Content, original)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MimeType should remain unchanged
|
||||||
|
if result.MimeType != "image/svg+xml" {
|
||||||
|
t.Fatalf("Expected MimeType to remain image/svg+xml, got %s", result.MimeType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue