mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 04:12:16 +01:00
chore(libreoffice): switch to supervisor (#708)
This commit is contained in:
@@ -151,7 +151,8 @@ func (b *chromiumBrowser) Start(logger *zap.Logger) error {
|
||||
|
||||
func (b *chromiumBrowser) Stop(logger *zap.Logger) error {
|
||||
if !b.isStarted.Load() {
|
||||
return errors.New("browser is already stopped")
|
||||
// No big deal? Like calling cancel twice.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Always remove the user profile directory created by Chromium.
|
||||
@@ -195,8 +196,11 @@ func (b *chromiumBrowser) Healthy(logger *zap.Logger) bool {
|
||||
b.ctxMu.RLock()
|
||||
defer b.ctxMu.RUnlock()
|
||||
|
||||
taskCtx, cancel := chromedp.NewContext(b.ctx)
|
||||
defer cancel()
|
||||
timeoutCtx, timeoutCancel := context.WithTimeout(b.ctx, time.Duration(10)*time.Second)
|
||||
defer timeoutCancel()
|
||||
|
||||
taskCtx, taskCancel := chromedp.NewContext(timeoutCtx)
|
||||
defer taskCancel()
|
||||
|
||||
err := chromedp.Run(taskCtx, chromedp.Navigate("about:blank"))
|
||||
if err != nil {
|
||||
|
||||
@@ -135,7 +135,7 @@ func TestChromiumBrowser_Stop(t *testing.T) {
|
||||
b.isStarted.Store(false)
|
||||
return b
|
||||
}(),
|
||||
expectError: true,
|
||||
expectError: false,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.scenario, func(t *testing.T) {
|
||||
@@ -927,7 +927,7 @@ func TestChromiumBrowser_pdf(t *testing.T) {
|
||||
expectedError: ErrPageRangesSyntaxError,
|
||||
},
|
||||
{
|
||||
scenario: "default options",
|
||||
scenario: "success (default options)",
|
||||
browser: newChromiumBrowser(
|
||||
browserArguments{
|
||||
binPath: os.Getenv("CHROMIUM_BIN_PATH"),
|
||||
|
||||
@@ -223,10 +223,10 @@ func (mod *Chromium) Descriptor() gotenberg.ModuleDescriptor {
|
||||
|
||||
var err error
|
||||
err = multierr.Append(err, fs.MarkDeprecated("chromium-user-agent", "use the extraHttpHeaders form field instead"))
|
||||
err = multierr.Append(err, fs.MarkDeprecated("chromium-failed-starts-threshold", "use the chromium-restart-after instead"))
|
||||
err = multierr.Append(err, fs.MarkDeprecated("chromium-failed-starts-threshold", "use the chromium-restart-after property instead"))
|
||||
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("create deprecated flags for the chromium module: %v", err))
|
||||
panic(fmt.Errorf("create deprecated flags for the Chromium module: %v", err))
|
||||
}
|
||||
|
||||
fs.Int64("chromium-restart-after", 0, "Number of conversions after which Chromium will automatically restart. Set to 0 to disable this feature")
|
||||
|
||||
@@ -192,7 +192,7 @@ func TestChromium_Validate(t *testing.T) {
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
scenario: "valid bin path",
|
||||
scenario: "validate success",
|
||||
binPath: os.Getenv("CHROMIUM_BIN_PATH"),
|
||||
expectError: false,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package chromium provides a module which adds routes for converting HTML
|
||||
// documents to Pdf. Other modules may also retrieve the [Api] provided by this
|
||||
// documents to PDF. Other modules may also retrieve the [Api] provided by this
|
||||
// module.
|
||||
package chromium
|
||||
|
||||
@@ -13,8 +13,8 @@ type ApiMock struct {
|
||||
PdfMock func(ctx context.Context, logger *zap.Logger, url, outputPath string, options Options) error
|
||||
}
|
||||
|
||||
func (api *ApiMock) Pdf(ctx context.Context, logger *zap.Logger, URL, outputPath string, options Options) error {
|
||||
return api.PdfMock(ctx, logger, URL, outputPath, options)
|
||||
func (api *ApiMock) Pdf(ctx context.Context, logger *zap.Logger, url, outputPath string, options Options) error {
|
||||
return api.PdfMock(ctx, logger, url, outputPath, options)
|
||||
}
|
||||
|
||||
// browserMock is a mock for the [browser] interface.
|
||||
|
||||
@@ -37,7 +37,6 @@ func TestFormDataChromiumPdfOptions(t *testing.T) {
|
||||
"foo",
|
||||
},
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
expectedOptions: func() Options {
|
||||
@@ -45,7 +44,6 @@ func TestFormDataChromiumPdfOptions(t *testing.T) {
|
||||
options.ExtraHttpHeaders = map[string]string{
|
||||
"User-Agent": "foo",
|
||||
}
|
||||
|
||||
return options
|
||||
}(),
|
||||
},
|
||||
@@ -58,7 +56,6 @@ func TestFormDataChromiumPdfOptions(t *testing.T) {
|
||||
"foo",
|
||||
},
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
expectedOptions: DefaultOptions(),
|
||||
@@ -72,7 +69,6 @@ func TestFormDataChromiumPdfOptions(t *testing.T) {
|
||||
`{"foo":"bar"}`,
|
||||
},
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
expectedOptions: func() Options {
|
||||
@@ -80,7 +76,6 @@ func TestFormDataChromiumPdfOptions(t *testing.T) {
|
||||
options.ExtraHttpHeaders = map[string]string{
|
||||
"foo": "bar",
|
||||
}
|
||||
|
||||
return options
|
||||
}(),
|
||||
},
|
||||
@@ -93,7 +88,6 @@ func TestFormDataChromiumPdfOptions(t *testing.T) {
|
||||
"foo",
|
||||
},
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
expectedOptions: DefaultOptions(),
|
||||
@@ -107,13 +101,11 @@ func TestFormDataChromiumPdfOptions(t *testing.T) {
|
||||
"screen",
|
||||
},
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
expectedOptions: func() Options {
|
||||
options := DefaultOptions()
|
||||
options.EmulatedMediaType = "screen"
|
||||
|
||||
return options
|
||||
}(),
|
||||
},
|
||||
@@ -156,7 +148,6 @@ func TestConvertUrlRoute(t *testing.T) {
|
||||
"",
|
||||
},
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
expectError: true,
|
||||
@@ -173,7 +164,6 @@ func TestConvertUrlRoute(t *testing.T) {
|
||||
"foo",
|
||||
},
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
api: &ApiMock{func(ctx context.Context, logger *zap.Logger, url, outputPath string, options Options) error {
|
||||
@@ -192,7 +182,6 @@ func TestConvertUrlRoute(t *testing.T) {
|
||||
"foo",
|
||||
},
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
api: &ApiMock{func(ctx context.Context, logger *zap.Logger, url, outputPath string, options Options) error {
|
||||
@@ -268,7 +257,6 @@ func TestConvertHtmlRoute(t *testing.T) {
|
||||
ctx.SetFiles(map[string]string{
|
||||
"index.html": "/index.html",
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
api: &ApiMock{func(ctx context.Context, logger *zap.Logger, url, outputPath string, options Options) error {
|
||||
@@ -285,7 +273,6 @@ func TestConvertHtmlRoute(t *testing.T) {
|
||||
ctx.SetFiles(map[string]string{
|
||||
"index.html": "/index.html",
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
api: &ApiMock{func(ctx context.Context, logger *zap.Logger, url, outputPath string, options Options) error {
|
||||
@@ -361,7 +348,6 @@ func TestConvertMarkdownRoute(t *testing.T) {
|
||||
ctx.SetFiles(map[string]string{
|
||||
"index.html": "/index.html",
|
||||
})
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
expectError: true,
|
||||
@@ -707,7 +693,6 @@ func TestConvertUrl(t *testing.T) {
|
||||
ctx: func() *api.ContextMock {
|
||||
ctx := &api.ContextMock{Context: new(api.Context)}
|
||||
ctx.SetCancelled(true)
|
||||
|
||||
return ctx
|
||||
}(),
|
||||
api: &ApiMock{func(ctx context.Context, logger *zap.Logger, url, outputPath string, options Options) error {
|
||||
|
||||
Reference in New Issue
Block a user