2023-06-03 19:33:06 +01:00
|
|
|
package favicons
|
|
|
|
|
|
|
|
import (
|
2023-06-05 17:26:56 +01:00
|
|
|
"bytes"
|
2023-06-03 19:33:06 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-06-05 17:26:56 +01:00
|
|
|
"image/png"
|
2023-06-03 19:33:06 +01:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFaviconList_PreProcess(t *testing.T) {
|
|
|
|
getFaviconViaRequest = func(_ string) ([]byte, error) {
|
|
|
|
return exampleSvg, nil
|
|
|
|
}
|
|
|
|
icons := &FaviconList{Svg: &FaviconImage{Url: "https://example.com/assets/logo.svg"}}
|
|
|
|
assert.NoError(t, icons.PreProcess(func(in []byte) ([]byte, error) {
|
|
|
|
return svg2png("inkscape", in)
|
|
|
|
}))
|
|
|
|
assert.Equal(t, "https://example.com/assets/logo.svg", icons.Svg.Url)
|
|
|
|
|
|
|
|
assert.Equal(t, "74cdc17d0502a690941799c327d9ca1ed042e76c784def43a42937f2eed270b4", icons.Svg.Hash)
|
2023-06-05 00:22:04 +01:00
|
|
|
assert.NotEqual(t, "", icons.Png.Hash)
|
|
|
|
assert.NotEqual(t, "", icons.Ico.Hash)
|
2023-06-05 17:26:56 +01:00
|
|
|
|
|
|
|
// verify png bytes are a valid png image
|
|
|
|
pngRaw := bytes.NewBuffer(icons.Png.Raw)
|
|
|
|
_, err := png.Decode(pngRaw)
|
|
|
|
assert.NoError(t, err)
|
2023-06-03 19:33:06 +01:00
|
|
|
}
|