Files
opencloud/services/webdav/pkg/config/parser/parse_test.go
T
Dominik Schmidt 17a9874be2 feat(webdav): make the Tika thumbnail preset configurable
OC_TIKA_THUMBNAIL_PRESET (WEBDAV_TIKA_THUMBNAIL_PRESET) names the catalog
preset webdav unpacks thumbnails with, "thumbnail" by default. A preset of
your own has to bring the same filter, only the raster images Tika marks as
THUMBNAIL or RENDERING, since webdav takes the first image in the answer.
An empty preset fails at startup.

Changing the preset needs the thumbnail cache emptied, as a Tika upgrade
does.
2026-12-02 16:22:19 +01:00

66 lines
2.3 KiB
Go

// Copyright 2026 OpenCloud GmbH <mail@opencloud.eu>
// SPDX-License-Identifier: Apache-2.0
package parser_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
thumbnailsdefaults "github.com/opencloud-eu/opencloud/services/thumbnails/pkg/config/defaults"
thumbnailsparser "github.com/opencloud-eu/opencloud/services/thumbnails/pkg/config/parser"
"github.com/opencloud-eu/opencloud/services/webdav/pkg/config/defaults"
"github.com/opencloud-eu/opencloud/services/webdav/pkg/config/parser"
)
var _ = Describe("ParseConfig", func() {
BeforeEach(func() {
GinkgoT().Setenv("OC_CONFIG_DIR", GinkgoT().TempDir())
})
// a body webdav allows and the generator refuses is downloaded and posted for nothing
DescribeTable("reads the maximum input file size the way the thumbnails service does",
func(env map[string]string, want string) {
for k, v := range env {
GinkgoT().Setenv(k, v)
}
cfg := defaults.DefaultConfig()
Expect(parser.ParseConfig(cfg)).To(Succeed())
generator := thumbnailsdefaults.DefaultConfig()
Expect(thumbnailsparser.ParseConfig(generator)).To(Succeed())
Expect(cfg.Thumbnails.MaxInputFileSize).To(Equal(want))
Expect(generator.Thumbnail.MaxInputImageFileSize).To(Equal(want))
},
Entry("from the shared name", map[string]string{
"OC_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE": "100MB",
}, "100MB"),
Entry("from the old name", map[string]string{
"THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE": "20MB",
}, "20MB"),
Entry("from the old name when both are set", map[string]string{
"THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE": "20MB",
"OC_THUMBNAILS_MAX_INPUT_IMAGE_FILE_SIZE": "100MB",
}, "20MB"),
)
It("refuses an empty Tika thumbnail preset", func() {
GinkgoT().Setenv("OC_TIKA_THUMBNAIL_PRESET", "")
Expect(parser.ParseConfig(defaults.DefaultConfig())).To(MatchError(ContainSubstring("OC_TIKA_THUMBNAIL_PRESET")))
})
It("takes the thumbnail preset by default and a configured one instead", func() {
cfg := defaults.DefaultConfig()
Expect(parser.ParseConfig(cfg)).To(Succeed())
Expect(cfg.TikaThumbnailPreset).To(Equal("thumbnail"))
GinkgoT().Setenv("WEBDAV_TIKA_THUMBNAIL_PRESET", "previews")
cfg = defaults.DefaultConfig()
Expect(parser.ParseConfig(cfg)).To(Succeed())
Expect(cfg.TikaThumbnailPreset).To(Equal("previews"))
})
})