mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 05:43:36 -05:00
Tika extracts audio cover art and GeoGebra thumbnails, so webdav no longer parses these files in-process. Without Tika they get no preview, and they are no longer announced by default.
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package preprocessor
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"golang.org/x/image/font"
|
|
"golang.org/x/image/font/opentype"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
func TestPreprocessor(t *testing.T) {
|
|
RegisterFailHandler(Fail)
|
|
RunSpecs(t, "Preprocessor Suite")
|
|
}
|
|
|
|
var _ = Describe("preprocessor", func() {
|
|
Describe("should decode text", func() {
|
|
var decoder TxtToImageConverter
|
|
BeforeEach(func() {
|
|
fontFaceOpts := &opentype.FaceOptions{
|
|
Size: 12,
|
|
DPI: 72,
|
|
Hinting: font.HintingNone,
|
|
}
|
|
|
|
fontLoader, err := NewFontLoader("", fontFaceOpts)
|
|
if err != nil {
|
|
fontLoader, _ = NewFontLoader("", fontFaceOpts)
|
|
}
|
|
decoder = TxtToImageConverter{
|
|
fontLoader: fontLoader,
|
|
}
|
|
})
|
|
It("renders the text as a png", func() {
|
|
img, err := decoder.Convert(bytes.NewReader([]byte("This is a test text")))
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(img.ContentType).To(Equal("image/png"))
|
|
Expect(img.Data).ToNot(BeEmpty())
|
|
})
|
|
|
|
It("fails if the font is missing", func() {
|
|
decoder.fontLoader.fontMapData = &FontMapData{
|
|
FMap: &FontMap{
|
|
DefaultFont: "/some/unknown/font.otf",
|
|
},
|
|
}
|
|
img, err := decoder.Convert(bytes.NewReader([]byte("This is a test text")))
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(img).To(BeNil())
|
|
})
|
|
})
|
|
|
|
Describe("ForType", func() {
|
|
It("hands an image to the generator as it is", func() {
|
|
Expect(ForType("image/png", Options{})).To(BeNil())
|
|
})
|
|
|
|
It("returns a TxtToImageConverter for text", func() {
|
|
Expect(ForType("text/plain", Options{})).To(BeAssignableToTypeOf(TxtToImageConverter{}))
|
|
})
|
|
|
|
It("hands an announced type without a converter to the generator, which says whether it reads it", func() {
|
|
Expect(ForType("application/pdf", Options{})).To(BeNil())
|
|
})
|
|
})
|
|
})
|