mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
fix(chromium): assets not loading
This commit is contained in:
@@ -1175,6 +1175,19 @@ Feature: /forms/chromium/convert/html
|
||||
Then the response status code should be 200
|
||||
Then the response header "Content-Type" should be "application/pdf"
|
||||
|
||||
# See: https://github.com/gotenberg/gotenberg/issues/1505.
|
||||
Scenario: POST /forms/chromium/convert/html (Asset)
|
||||
Given I have a default Gotenberg container
|
||||
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s):
|
||||
| files | testdata/html-with-asset/index.html | file |
|
||||
| files | testdata/html-with-asset/image.png | file |
|
||||
| Gotenberg-Output-Filename | foo | header |
|
||||
Then the response status code should be 200
|
||||
Then the response header "Content-Type" should be "application/pdf"
|
||||
Then there should be 1 PDF(s) in the response
|
||||
Then the "foo.pdf" PDF should have 1 page(s)
|
||||
Then the "foo.pdf" PDF should have 1 image(s)
|
||||
|
||||
# See: https://github.com/gotenberg/gotenberg/issues/1500.
|
||||
Scenario: POST /forms/chromium/convert/html (Long Filename)
|
||||
Given I have a default Gotenberg container
|
||||
|
||||
@@ -952,6 +952,39 @@ func (s *scenario) thePdfShouldHavePages(ctx context.Context, name string, pages
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) thePdfShouldHaveImages(ctx context.Context, name string, images int) error {
|
||||
path := fmt.Sprintf("%s/%s/%s", s.workdir, s.resp.Header().Get("Gotenberg-Trace"), name)
|
||||
|
||||
_, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("PDF %q does not exist", path)
|
||||
}
|
||||
|
||||
cmd := []string{
|
||||
"pdfimages",
|
||||
"-list",
|
||||
filepath.Base(path),
|
||||
}
|
||||
|
||||
output, err := execCommandInIntegrationToolsContainer(ctx, cmd, path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("exec %q: %w", cmd, err)
|
||||
}
|
||||
|
||||
// pdfimages -list outputs a header (2 lines) then one line per image.
|
||||
lines := strings.Split(strings.TrimSpace(output), "\n")
|
||||
actual := 0
|
||||
if len(lines) > 2 {
|
||||
actual = len(lines) - 2
|
||||
}
|
||||
|
||||
if actual != images {
|
||||
return fmt.Errorf("expected %d image(s), but actual is %d", images, actual)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) thePdfShouldBeSetToLandscapeOrientation(ctx context.Context, name string, kind string) error {
|
||||
var path string
|
||||
if !strings.HasPrefix(name, "*_") {
|
||||
@@ -1270,6 +1303,7 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
|
||||
ctx.Then(`^the "([^"]*)" PDF should have (\d+) page\(s\)$`, s.thePdfShouldHavePages)
|
||||
ctx.Then(`^the "([^"]*)" PDF (should|should NOT) be set to landscape orientation$`, s.thePdfShouldBeSetToLandscapeOrientation)
|
||||
ctx.Then(`^the "([^"]*)" PDF (should|should NOT) have the following content at page (\d+):$`, s.thePdfShouldHaveTheFollowingContentAtPage)
|
||||
ctx.Then(`^the "([^"]*)" PDF should have (\d+) image\(s\)$`, s.thePdfShouldHaveImages)
|
||||
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
|
||||
if s.gotenbergContainer != nil {
|
||||
errTerminate := s.gotenbergContainer.Terminate(ctx, testcontainers.StopTimeout(0))
|
||||
|
||||
BIN
test/integration/testdata/html-with-asset/image.png
vendored
Normal file
BIN
test/integration/testdata/html-with-asset/image.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 69 B |
11
test/integration/testdata/html-with-asset/index.html
vendored
Normal file
11
test/integration/testdata/html-with-asset/index.html
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>HTML with Asset</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Asset test</p>
|
||||
<img src="image.png" alt="Test image" />
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user