diff --git a/.github/actions/build-test-push/test.sh b/.github/actions/build-test-push/test.sh index 1bbaec95..097f816b 100755 --- a/.github/actions/build-test-push/test.sh +++ b/.github/actions/build-test-push/test.sh @@ -82,5 +82,9 @@ run_cmd "$cmd" cmd="make test-integration DOCKER_REPOSITORY=$repository GOTENBERG_VERSION=$version PLATFORM=$platform CONCURRENCY=3 VARIANT=libreoffice TAGS=libreoffice" run_cmd "$cmd" +# The corpus runs realistic documents against the full image only. +cmd="make test-corpus DOCKER_REPOSITORY=$repository GOTENBERG_VERSION=$version PLATFORM=$platform CONCURRENCY=3" +run_cmd "$cmd" + echo "✅ Done!" exit 0 diff --git a/.prettierignore b/.prettierignore index a72a816a..c800d1e0 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,8 +1,8 @@ build # The corpus fixtures keep the bytes their generators wrote: the manifest records their sizes. -test/integration/testdata/corpus/web -test/integration/testdata/corpus/office -test/integration/testdata/corpus/pdf -test/integration/testdata/corpus/generators/i18n.json +test/corpus/testdata/web +test/corpus/testdata/office +test/corpus/testdata/pdf +test/corpus/testdata/generators/i18n.json # Its tables hold cells of several hundred characters, which Prettier would pad onto every row. -test/integration/testdata/corpus/MANIFEST.md +test/corpus/MANIFEST.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c07c2533..d5b28783 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,6 +29,7 @@ pkg/gotenberg/ -> Core module system, interfaces, utilities, mocks. pkg/modules/ -> Feature modules (api, chromium, libreoffice, pdf, etc.). pkg/standard/ -> Wires all standard modules together via imports. test/integration/ -> Gherkin feature files + Go test infrastructure. +test/corpus/ -> Release QA corpus: realistic documents, one feature file per engine. build/ -> Dockerfile, fonts, Chromium config. .bruno/ -> Bruno API collection (mirrors every route). ``` @@ -50,6 +51,7 @@ All build and verification tasks go through the Makefile. Do not run `go` comman | `make lint-todo` | Find TODOs in Go code | Before committing | | `make test-unit` | Run unit tests | Before committing | | `make test-integration` | Run all integration tests (40 min timeout) | Before committing | +| `make test-corpus` | Run the release QA corpus (40 min timeout) | When a change can alter how real documents come out | | `make godoc` | Serve GoDoc at `localhost:6060` | To verify documentation | | `make run` | Run a Gotenberg container via `docker compose` | Manual testing. Flags configured via Makefile variables and compose.yaml | | `make telemetry` | Start an OpenTelemetry collector and OpenObserve | When testing telemetry locally | @@ -155,6 +157,8 @@ Gherkin (BDD) via Godog with `testcontainers-go` for Docker orchestration. Featu `make build` is required before running integration tests. The full suite has a 40-minute timeout, so run only the tag(s) relevant to your change. +The release QA corpus is a separate suite, `make test-corpus`, that runs realistic documents with recorded facts; see `test/corpus/README.md`. + ## Pull requests ### Commits @@ -180,4 +184,5 @@ Before opening the PR, confirm: ## Further reading - [`test/integration/README.md`](test/integration/README.md) — Gherkin step reference, available tags, writing new tests. +- [`test/corpus/README.md`](test/corpus/README.md) — release QA corpus: realistic documents, their manifest, how to add a fixture. - [`.bruno/README.md`](.bruno/README.md) — `.bru` file format, conventions, route update checklist. diff --git a/Makefile b/Makefile index 7e669457..ac244bf5 100644 --- a/Makefile +++ b/Makefile @@ -164,10 +164,6 @@ KEEP_FAILED= # chromium-screenshot-markdown # chromium-screenshot-url # chromium-ssrf -# corpus -# corpus-chromium -# corpus-libreoffice -# corpus-pdf # debug # health # libreoffice @@ -211,6 +207,19 @@ test-integration: ## Run integration tests (automatically retries failed scenari --keep-failed="$(KEEP_FAILED)" \ --tags="$(TAGS)" +# Tags of the corpus suite: chromium, libreoffice, pdf. TAGS selects among them +# for test-corpus, as it does among the integration tags for test-integration. +.PHONY: test-corpus +test-corpus: ## Run the release QA corpus (realistic documents, automatically retries failed scenarios up to 3 times) + go test -timeout 40m -tags=corpus -v github.com/gotenberg/gotenberg/v9/test/corpus -args \ + --gotenberg-docker-repository=$(DOCKER_REPOSITORY) \ + --gotenberg-version=$(GOTENBERG_VERSION) \ + --gotenberg-variant=$(VARIANT) \ + --gotenberg-container-platform=$(PLATFORM) \ + --concurrency=$(CONCURRENCY) \ + --keep-failed="$(KEEP_FAILED)" \ + --tags="$(TAGS)" + # golangci-lint runs at a pinned version, so a Homebrew upgrade cannot move the # findings under the zero-warnings policy. An env var of the same name overrides # it. diff --git a/test/integration/testdata/corpus/MANIFEST.md b/test/corpus/MANIFEST.md similarity index 97% rename from test/integration/testdata/corpus/MANIFEST.md rename to test/corpus/MANIFEST.md index 0870c4da..3874cebb 100644 --- a/test/integration/testdata/corpus/MANIFEST.md +++ b/test/corpus/MANIFEST.md @@ -1,6 +1,6 @@ # Gotenberg v9 QA corpus manifest -Root: `test/integration/testdata/corpus`. Generators in `generators/` (see its README). Page counts marked "(LO)" were measured by converting with the LibreOffice in the gotenberg:snapshot image and `pdfinfo`; "expected" counts were not measured. +Root: `test/corpus/testdata`; the file paths below are relative to it. Generators in `generators/` (see its README). Page counts marked "(LO)" were measured by converting with the LibreOffice in the gotenberg:snapshot image and `pdfinfo`; "expected" counts were not measured. ## web/ (Chromium routes) diff --git a/test/integration/testdata/corpus/README.md b/test/corpus/README.md similarity index 57% rename from test/integration/testdata/corpus/README.md rename to test/corpus/README.md index 4cc9d8f6..adf7b42e 100644 --- a/test/integration/testdata/corpus/README.md +++ b/test/corpus/README.md @@ -1,31 +1,36 @@ # Release QA corpus -Realistic documents with known contents, and the facts the integration tests assert about them. `corpus.feature` turns the black-box QA of Gotenberg 9.0.0 into a regression suite that runs against every image. +Realistic documents with known contents, and the facts the scenarios assert about them. This suite turns the black-box QA of Gotenberg 9.0.0 into a regression suite that runs against the full image. It is separate from the quick per-route scenarios of [`test/integration/`](../integration/README.md), and shares their step library and runner. ## Why -The other fixtures in `testdata/` are minimal: a page with a marker, a form with one field. They prove that a route answers. They say nothing about what a 10-page contract, a 3-sheet budget, a deck with a hidden slide, a multilingual page or an encrypted report comes out as. +The fixtures of `test/integration/testdata/` are minimal: a page with a marker, a form with one field. They prove that a route answers. They say nothing about what a 10-page contract, a 3-sheet budget, a deck with a hidden slide, a multilingual page or an encrypted report comes out as. The 9.0.0 release QA converted such documents, about 80 files, through every route and option, and compared the output with what each document contains. It found defects the minimal fixtures could not: a CSV converted to one cell per line, a Factur-X invoice embedded without a check, a truncated PDF that `metadata` accepted, element backgrounds that the docs described wrong. Keeping the documents here, with their facts written down, means the next change to Gotenberg, lok, litho, Chromium or LibreOffice runs against the same documents and the same facts. +The rule: a file that exists to exercise one field belongs in `test/integration/testdata/`; a document that stands for a real user file, with its facts in the manifest, belongs in `test/corpus/testdata/`. + Each fact is known by construction or measured once. A generated document knows its page breaks, markers, metadata and sizes because the script wrote them. A fact the engine decides, such as the page count of a text file, was measured on the image and recorded as measured, not as hoped. [`MANIFEST.md`](MANIFEST.md) lists every file with its format, what it contains and what a scenario can assert, then where the image differs from the document's intent. ## What is in it +Under `testdata/`: + - `web/`, for the Chromium routes: sites with their assets, CSS page sizes and breaks, a header and a footer, a delayed render, a console error, a Markdown bundle, a long landing page, multilingual text, a wide table, and the invoice site as a ZIP archive. - `office/`, for the LibreOffice route: the same memo, figures and pitch across fifteen formats, a contract, a budget, a deck with a hidden slide and notes, a CSV, tracked changes, a form, plain text, a letter, and images in seven formats. - `pdf/`, for the PDF routes: a report with text at known coordinates for redaction and stamps, an annex to merge, a letterhead, transparency, CMYK colors, an image-heavy file, AES and RC4 encrypted copies, a CII invoice, a certificate, a stamp image and an attachment. -- `generators/`: the scripts that wrote the generated files, and the commands that made the hand-made ones. See its [README](generators/README.md). +- `generators/`: the scripts that wrote the generated files, and the commands that made the hand-made ones. See its [README](testdata/generators/README.md). ## How the scenarios use it -`test/integration/features/corpus.feature` carries the `@corpus` tag, and each scenario one of `@corpus-chromium`, `@corpus-libreoffice` and `@corpus-pdf`. A scenario sends one document, or one list of stages, and asserts the manifest's facts on the answer: the page count, the page size in points, the text on a given page, the metadata, the outline, the number of images, the embedded files, PDF/A conformance, the Factur-X XMP. Two scenario outlines cover the format variants of the memo, the figures and the pitch, and the image inputs. +`features/` holds one file per engine: `chromium.feature`, `libreoffice.feature` and `pdf.feature`, tagged `@chromium`, `@libreoffice` and `@pdf`. A scenario sends one document, or one list of stages, and asserts the manifest's facts on the answer: the page count, the page size in points, the text on a given page, the metadata, the outline, the number of images, the embedded files, PDF/A conformance, the Factur-X XMP. Two scenario outlines cover the format variants of the memo, the figures and the pitch, and the image inputs. ```bash make build -make test-integration TAGS=corpus -make test-integration TAGS=corpus-libreoffice -make test-integration TAGS=corpus-pdf KEEP_FAILED=/tmp/failed +make test-corpus +make test-corpus TAGS=chromium +make test-corpus TAGS=libreoffice +make test-corpus TAGS=pdf KEEP_FAILED=/tmp/failed ``` A scenario asserts what the image produces, and the manifest says when that differs from the document's intent: `readme.txt` paginates to 4 pages, a spreadsheet cell clips its text to `REVENUE-SH`, the deleted text of a tracked change is absent. When a fix changes such an outcome, update the manifest and the scenario together. @@ -35,12 +40,12 @@ A scenario asserts what the image produces, and the manifest says when that diff 1. Generate the document with a script in `generators/`, so its facts are known by construction, and check in the script with the file. A file made once by hand, such as an encrypted copy or a certificate, goes in the "Not scripted" list of `generators/README.md` with the command that made it. 2. Put a unique marker in every region a scenario reads (`REPORT-PAGE-2`, `COSTS-SHEET-MARKER`), not prose: text extraction keeps a marker intact across fonts, scripts and line breaks. 3. Record the file in `MANIFEST.md`: format, contents, and the facts a scenario can assert. Measure a page count on the image rather than expecting it, and say so. -4. Write the scenario in `corpus.feature` under the engine's tag, asserting those facts, before any Go change. Reuse the steps listed in [`test/integration/README.md`](../../README.md), and add one there only when no existing step reads the fact. -5. Keep the corpus small. It weighs 2 MB: share an asset between files rather than embedding a new one, and prefer an existing `testdata/` file over a copy. The manifest's "Left out" list names the ones the corpus reuses. -6. Run `make test-integration TAGS=corpus-` and `make lint-prettier`. +4. Write the scenario in the engine's file under `features/`, asserting those facts, before any Go change. Reuse the steps listed in [`test/integration/README.md`](../integration/README.md), and add one there only when no existing step reads the fact. +5. Keep the corpus small. It weighs 2 MB: share an asset between files rather than embedding a new one, and prefer an existing `test/integration/testdata/` file over a copy. The manifest's "Left out" list names the ones the corpus reuses. +6. Run `make test-corpus TAGS=` and `make lint-prettier`. `.prettierignore` excludes the fixtures: the manifest records their byte sizes, and the HTML and CSS are what the generators wrote. Don't reformat them. ## What it is not -The per-route feature files stay the place for one field or one stage at a time, every error message, and every edge of the API. The corpus asserts outcomes on realistic documents end to end. It is not a benchmark either: it runs against the same image as the other scenarios, and its timings mean nothing. +The per-route feature files of `test/integration/` stay the place for one field or one stage at a time, every error message, and every edge of the API. The corpus asserts outcomes on realistic documents end to end. It is not a benchmark either: it runs against the same image as the integration scenarios, and its timings mean nothing. diff --git a/test/corpus/features/chromium.feature b/test/corpus/features/chromium.feature new file mode 100644 index 00000000..346e50d0 --- /dev/null +++ b/test/corpus/features/chromium.feature @@ -0,0 +1,270 @@ +@chromium +Feature: Chromium corpus + Realistic web documents with known contents, described in testdata/MANIFEST.md. + Each scenario sends a site, a page or a Markdown bundle through the Chromium routes. + + # The page break comes from the CSS (`break-before: page` on the payment terms heading) and + # the size from `@page { size: A4 }`. + Scenario: Invoice site (2 A4 pages) + 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/web/invoice/index.html | file | + | files | testdata/web/invoice/style.css | file | + | files | testdata/web/invoice/logo.png | file | + | files | testdata/web/invoice/header.html | file | + | files | testdata/web/invoice/footer.html | file | + | preferCssPageSize | true | field | + | printBackground | true | field | + | nativeBookmarks | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 2 page(s) + Then the "foo.pdf" PDF page 1 should be 595.28x841.89 points + Then the "foo.pdf" PDF page 2 should be 595.28x841.89 points + Then the "foo.pdf" PDF should have the "Title" metadata set to "Invoice INV-2026-0042" + Then the "foo.pdf" PDF should have a document outline + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Northwind Traders + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Contoso Ltd + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + 4,620.00 EUR + """ + Then the "foo.pdf" PDF should NOT have the following content at page 1: + """ + Payment terms + """ + Then the "foo.pdf" PDF should have content matching "Page\s*1\s*of\s*2" at page 1 + Then the "foo.pdf" PDF should have content matching "Page\s*2\s*of\s*2" at page 2 + Then the "foo.pdf" PDF should have the following content at page 2: + """ + Payment terms + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + IBAN FR76 3000 6000 0112 3456 7890 189 + """ + + Scenario: Invoice site from a ZIP archive + 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): + | archives | testdata/web/site.zip | file | + | preferCssPageSize | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 2 page(s) + Then the "foo.pdf" PDF page 1 should be 595.28x841.89 points + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Invoice INV-2026-0042 + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + IBAN FR76 3000 6000 0112 3456 7890 189 + """ + + Scenario: Delayed content waits for an expression + 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/web/wait/index.html | file | + | waitForExpression | window.chartReady === true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Revenue: 42,000 EUR + """ + Then the "foo.pdf" PDF should NOT have the following content at page 1: + """ + Loading + """ + + # The exception happens after the render: the page converts unless the flag is set. + Scenario: A console exception fails the conversion + 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/web/console-error/index.html | file | + | failOnConsoleExceptions | true | field | + Then the response status code should be 409 + Then the response body should contain string: + """ + Chromium console exceptions + """ + 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/web/console-error/index.html | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Console error page + """ + + # The inline script sets the title to "pwned" if it runs. The title stays the one of the + # template and the text right after the script survives. + Scenario: Markdown bundle keeps the text and the title + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/markdown" endpoint with the following form data and header(s): + | files | testdata/web/markdown/index.html | file | + | files | testdata/web/markdown/release-notes.md | file | + | files | testdata/web/markdown/changelog.md | file | + | files | testdata/web/markdown/style.css | file | + | files | testdata/web/markdown/screenshot.png | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have the "Title" metadata set to "Release notes 9.0.0" + Then the "foo.pdf" PDF should have 2 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Release notes 9.0.0 + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + CODE-BLOCK-MARKER + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + DONE-TASK + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + OPEN-TASK + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Removed legacy flag + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + SANITIZE-ME-MARKER + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + CHANGELOG-V9 + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + CHANGELOG-V8 + """ + Then the "foo.pdf" PDF should have 1 image(s) + + # The navigation is hidden in print, and a block shows only from a 1200 px viewport. + Scenario: Landing page: print media and viewport width + 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/web/landing/index.html | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Start free trial + """ + Then the "foo.pdf" PDF should NOT have the following content at page 1: + """ + Pricing + """ + Then the "foo.pdf" PDF should NOT have the following content at page 1: + """ + WIDE-LAYOUT-MARKER + """ + 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/web/landing/index.html | file | + | paperWidth | 14 | field | + | paperHeight | 11 | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have the following content at page 1: + """ + WIDE-LAYOUT-MARKER + """ + 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/web/landing/index.html | file | + | singlePage | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Start free trial + """ + + # The Latin marker of a right-to-left line can come out as ":AR": the patterns accept both. + Scenario: Multilingual page renders every script + 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/web/i18n/index.html | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Multilingual + """ + Then the "foo.pdf" PDF should have content matching "AR:|:AR" at page 1 + Then the "foo.pdf" PDF should have content matching "HE:|:HE" at page 1 + Then the "foo.pdf" PDF should have content matching "ZH:|:ZH" at page 1 + Then the "foo.pdf" PDF should have content matching "JA:|:JA" at page 1 + Then the "foo.pdf" PDF should have content matching "KO:|:KO" at page 1 + Then the "foo.pdf" PDF should have content matching "TH:|:TH" at page 1 + Then the "foo.pdf" PDF should have content matching "HI:|:HI" at page 1 + Then the "foo.pdf" PDF should have content matching "EL:|:EL" at page 1 + Then the "foo.pdf" PDF should have content matching "RU:|:RU" at page 1 + Then the "foo.pdf" PDF should have content matching "EMOJI:|:EMOJI" at page 1 + Then the "foo.pdf" PDF should have content matching "MATH:|:MATH" at page 1 + + Scenario: Print CSS handbook gives A5 pages + 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/web/print-css/index.html | file | + | files | testdata/web/print-css/print.css | file | + | preferCssPageSize | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 4 page(s) + Then the "foo.pdf" PDF page 1 should be 419.53x595.28 points + Then the "foo.pdf" PDF page 4 should be 419.53x595.28 points + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Handbook + """ + Then the "foo.pdf" PDF should NOT have the following content at page 1: + """ + NAV-MARKER + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + CHAPTER-ONE + """ + Then the "foo.pdf" PDF should have the following content at page 3: + """ + CHAPTER-TWO + """ + Then the "foo.pdf" PDF should have the following content at page 4: + """ + CHAPTER-THREE + """ + + Scenario: Wide table on a single page + 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/web/wide-table/index.html | file | + | singlePage | true | field | + | landscape | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the "Title" metadata set to "Wide table" + Then the "foo.pdf" PDF should have the following content at page 1: + """ + C01 + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + r40c30 + """ diff --git a/test/corpus/features/libreoffice.feature b/test/corpus/features/libreoffice.feature new file mode 100644 index 00000000..38436220 --- /dev/null +++ b/test/corpus/features/libreoffice.feature @@ -0,0 +1,293 @@ +@libreoffice +Feature: LibreOffice corpus + Realistic office documents with known contents, described in testdata/MANIFEST.md. + Each scenario sends a contract, a budget, a deck, a text file or an image through the LibreOffice route. + + Scenario: Contract DOCX (10 pages) + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/contract.docx | file | + | nativeBookmarks | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 10 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Master Services Agreement + """ + Then the "foo.pdf" PDF should have the following content at page 10: + """ + Schedule A + """ + Then the "foo.pdf" PDF should NOT have the following content at page 1: + """ + Schedule A + """ + Then the "foo.pdf" PDF should have the "Title" metadata set to "Master Services Agreement" + Then the "foo.pdf" PDF should have the "Author" metadata set to "Legal Department" + Then the "foo.pdf" PDF should have the "Subject" metadata set to "Services" + Then the "foo.pdf" PDF should have the "Keywords" metadata set to "contract, msa" + Then the "foo.pdf" PDF should have a document outline + Then the "foo.pdf" PDF should have content matching "Page" at page 1 + + # The first column clips long cells ("Cloud host"). The Monthly sheet spans two pages; `singlePage` fits each sheet on one page. + Scenario: Budget XLSX (3 sheets) + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/budget.xlsx | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 4 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + FY2026 Budget + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Cloud host + """ + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/budget.xlsx | file | + | singlePage | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + FY2026 Budget + """ + Then the "foo.pdf" PDF should have the following content at page 3: + """ + Budget not + """ + Then the "foo.pdf" PDF should have the following content at page 3: + """ + Prepared + """ + + Scenario: Deck PPTX without the hidden slide, then with notes pages + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/deck.pptx | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 7 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Q4 Product Review + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + Agenda + """ + Then the "foo.pdf" PDF should have the following content at page 4: + """ + R2C2 + """ + Then the "foo.pdf" PDF should have the following content at page 7: + """ + Thank you + """ + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 1 + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 2 + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 3 + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 4 + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 5 + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 6 + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 7 + Then the "foo.pdf" PDF should NOT have content matching "NOTES-MARKER" at page 2 + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/deck.pptx | file | + | exportNotesPages | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 14 page(s) + Then the "foo.pdf" PDF should have the following content at page 9: + """ + NOTES-MARKER-2 + """ + Then the "foo.pdf" PDF should have the following content at page 14: + """ + NOTES-MARKER-8 + """ + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 7 + Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 13 + + # Fails until lok passes the CSV import options: every line lands in one cell today. + Scenario: CSV keeps its columns + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/sales.csv | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have the following content at page 1: + """ + customer + """ + Then the "foo.pdf" PDF should NOT have the following content at page 1: + """ + id,date,customer + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Café Müller + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Straße GmbH + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Élodie & Fils + """ + + Scenario: Tracked changes keep the inserted text + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/tracked.docx | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + INSERTED-TEXT + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + End of sentence. + """ + + Scenario: Multilingual DOCX + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/i18n.docx | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Multilingual document + """ + Then the "foo.pdf" PDF should have content matching "AR:|:AR" at page 1 + Then the "foo.pdf" PDF should have content matching "HE:|:HE" at page 1 + Then the "foo.pdf" PDF should have content matching "ZH:|:ZH" at page 1 + Then the "foo.pdf" PDF should have content matching "JA:|:JA" at page 1 + Then the "foo.pdf" PDF should have content matching "KO:|:KO" at page 1 + Then the "foo.pdf" PDF should have content matching "TH:|:TH" at page 1 + Then the "foo.pdf" PDF should have content matching "HI:|:HI" at page 1 + Then the "foo.pdf" PDF should have content matching "EL:|:EL" at page 1 + Then the "foo.pdf" PDF should have content matching "RU:|:RU" at page 1 + Then the "foo.pdf" PDF should have content matching "EMOJI:|:EMOJI" at page 1 + Then the "foo.pdf" PDF should have content matching "MATH:|:MATH" at page 1 + + Scenario: Form ODT keeps its text + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/form.odt | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + FORM-DOC-MARKER + """ + + # The manifest counted 3 pages with another LibreOffice build; the image gives 4. + Scenario: Plain text paginates + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/readme.txt | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 4 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Line 01: + """ + Then the "foo.pdf" PDF should have the following content at page 4: + """ + Line 60: + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Café résumé naïve déjà vu + """ + + Scenario: WebP is not an accepted input + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/images/pic.webp | file | + Then the response status code should be 400 + Then the response body should contain string: + """ + Invalid form data: no form file found for extensions: + """ + + Scenario Outline: Office formats convert with the documented pages and text + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/ | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have page(s) + Then the "foo.pdf" PDF should have the following content at page : + """ + + """ + + Examples: + | file | pages | page | marker | + | memo.fodt | 1 | 1 | MEMO-END-MARKER | + | memo.odt | 1 | 1 | MEMO-END-MARKER | + | memo.doc | 1 | 1 | MEMO-END-MARKER | + | memo.rtf | 1 | 1 | MEMO-END-MARKER | + | memo-lo.docx | 1 | 1 | MEMO-END-MARKER | + | memo.html | 1 | 1 | MEMO-END-MARKER | + | memo.pdf | 1 | 1 | MEMO-END-MARKER | + | figures.fods | 2 | 1 | REVENUE-SH | + | figures.fods | 2 | 2 | COSTS-SHEE | + | figures.ods | 2 | 1 | REVENUE-SH | + | figures.ods | 2 | 2 | COSTS-SHEE | + | figures.xls | 2 | 1 | REVENUE-SH | + | figures.xls | 2 | 2 | COSTS-SHEE | + | figures-lo.xlsx | 2 | 1 | REVENUE-SH | + | figures-lo.xlsx | 2 | 2 | COSTS-SHEE | + | pitch.fodp | 4 | 1 | PITCH-1 | + | pitch.fodp | 4 | 4 | PITCH-4 | + | pitch.odp | 4 | 1 | PITCH-1 | + | pitch.odp | 4 | 4 | PITCH-4 | + | pitch.ppt | 4 | 1 | PITCH-1 | + | pitch.ppt | 4 | 4 | PITCH-4 | + | pitch-lo.pptx | 4 | 1 | PITCH-1 | + | pitch-lo.pptx | 4 | 4 | PITCH-4 | + | letter.rtf | 1 | 1 | Northwind Traders | + | letter.rtf | 1 | 1 | Second item | + | page.htm | 1 | 1 | HTM-MARKER | + | data.xml | 1 | 1 | XML-MARKER | + | data.xml | 1 | 1 | Second | + + Scenario Outline: Image formats convert to a one-page PDF + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/images/ | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + 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) + + Examples: + | file | + | photo.jpg | + | diagram.png | + | icon.gif | + | scan.tif | + | pic.bmp | + + Scenario: SVG converts to a one-page PDF + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): + | files | testdata/office/images/logo.svg | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) diff --git a/test/corpus/features/pdf.feature b/test/corpus/features/pdf.feature new file mode 100644 index 00000000..aa453ab2 --- /dev/null +++ b/test/corpus/features/pdf.feature @@ -0,0 +1,247 @@ +@pdf +Feature: PDF corpus + Realistic PDF files with known contents, described in testdata/MANIFEST.md. + Each scenario sends a report, an annex, an invoice or an encrypted copy through the PDF routes. + + Scenario: Report PDF: info and metadata + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + Then the response status code should be 200 + Then the response body should match JSON: + """ + { + "report.pdf": { + "pages": 3, + "version": "ignore", + "encrypted": false, + "tagged": false, + "linearized": false, + "formFields": false + } + } + """ + When I make a "POST" request to Gotenberg at the "/forms/pdf/metadata" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + Then the response status code should be 200 + Then the response body should match JSON: + """ + { + "report.pdf": { + "title": "Quarterly Report", + "author": "Finance" + } + } + """ + When I make a "POST" request to Gotenberg at the "/forms/pdf/merge" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF page 1 should be 612x792 points + Then the "foo.pdf" PDF page 3 should be 612x792 points + Then the "foo.pdf" PDF should have the "Title" metadata set to "Quarterly Report" + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Body line 1 of page 1 + """ + Then the "foo.pdf" PDF should have the following content at page 3: + """ + REPORT-PAGE-3 + """ + + Scenario: Redaction removes the label of page 1 only + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/redact" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + | regions | [{"page":1,"x":70,"y":388,"width":300,"height":42}] | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF should NOT have the following content at page 1: + """ + REPORT-PAGE-1 + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Quarterly Report + """ + Then the "foo.pdf" PDF should have the following content at page 1: + """ + Body line 1 of page 1 + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + REPORT-PAGE-2 + """ + Then the "foo.pdf" PDF should have the following content at page 3: + """ + REPORT-PAGE-3 + """ + Then the "foo.pdf" PDF page 1 should be 612x792 points + + # Inputs merge in the order of their filenames, so the annex comes first. + Scenario: Merge report and annex + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/merge" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + | files | testdata/pdf/annex.pdf | file | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 5 page(s) + Then the "foo.pdf" PDF page 5 should be 612x792 points + Then the "foo.pdf" PDF should have the following content at page 1: + """ + ANNEX-PAGE-1 + """ + Then the "foo.pdf" PDF should have the following content at page 2: + """ + ANNEX-PAGE-2 + """ + Then the "foo.pdf" PDF should have the following content at page 3: + """ + REPORT-PAGE-1 + """ + Then the "foo.pdf" PDF should have the following content at page 4: + """ + REPORT-PAGE-2 + """ + Then the "foo.pdf" PDF should have the following content at page 5: + """ + REPORT-PAGE-3 + """ + + Scenario: Stamp text and image + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/stamp-text" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + | text | APPROVED-STAMP | field | + | pages | 1 | field | + | x | 72 | field | + | y | 200 | field | + | fontSize | 24 | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + REPORT-PAGE-1 + """ + When I make a "POST" request to Gotenberg at the "/forms/pdf/stamp-image" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + | files | testdata/pdf/stamp.jpg | file | + | image | stamp.jpg | field | + | pages | 1 | field | + | width | 150 | field | + | height | 50 | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF should have 1 image(s) + + Scenario: Letterhead stamped under the report + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/stamp-pdf" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + | files | testdata/pdf/letterhead.pdf | file | + | source | letterhead.pdf | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + REPORT-PAGE-1 + """ + + Scenario: Encrypted PDF needs its password + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s): + | files | testdata/pdf/encrypted.pdf | file | + Then the response status code should be 400 + When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s): + | files | testdata/pdf/encrypted.pdf | file | + | password | secret | field | + Then the response status code should be 200 + Then the response body should match JSON: + """ + { + "encrypted.pdf": { + "pages": 3, + "encrypted": true + } + } + """ + When I make a "POST" request to Gotenberg at the "/forms/pdf/decrypt" endpoint with the following form data and header(s): + | files | testdata/pdf/encrypted.pdf | file | + Then the response status code should be 400 + When I make a "POST" request to Gotenberg at the "/forms/pdf/decrypt" endpoint with the following form data and header(s): + | files | testdata/pdf/encrypted.pdf | file | + | password | secret | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response PDF(s) should NOT be encrypted + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF should have the following content at page 3: + """ + REPORT-PAGE-3 + """ + When I make a "POST" request to Gotenberg at the "/forms/pdf/decrypt" endpoint with the following form data and header(s): + | files | testdata/pdf/encrypted-rc4.pdf | file | + | password | secret | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response PDF(s) should NOT be encrypted + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF should have the following content at page 2: + """ + REPORT-PAGE-2 + """ + + Scenario: Factur-X embeds the CII invoice + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/remediate" endpoint with the following form data and header(s): + | files | testdata/pdf/report.pdf | file | + | files | testdata/pdf/invoice-cii.xml | file | + | profile | Factur-X | field | + | xml | invoice-cii.xml | field | + | level | EN 16931 | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response header "Gotenberg-Remediation-Residual" should be "0" + Then the "foo.pdf" PDF should have 3 page(s) + Then the "foo.pdf" PDF should have the "Title" metadata set to "Quarterly Report" + Then the response PDF(s) should be valid "PDF/A-3b" with a tolerance of 0 failed rule(s) + Then the response PDF(s) should have the "factur-x.xml" file embedded with relationship "Alternative" + Then the response PDF(s) should declare Factur-X XMP with conformance level "EN 16931" + + Scenario: Transparency remediates to PDF/A-2b + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/remediate" endpoint with the following form data and header(s): + | files | testdata/pdf/transparent.pdf | file | + | profile | PDF/A-2b | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the "foo.pdf" PDF should have 1 page(s) + Then the "foo.pdf" PDF should have the following content at page 1: + """ + TRANSPARENT-MARKER + """ + Then the response PDF(s) should be valid "PDF/A-2b" with a tolerance of 0 failed rule(s) + + Scenario: Color and image-heavy samples read back + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s): + | files | testdata/pdf/colors.pdf | file | + | files | testdata/pdf/image-heavy.pdf | file | + Then the response status code should be 200 + Then the response body should match JSON: + """ + { + "colors.pdf": { + "pages": 1 + }, + "image-heavy.pdf": { + "pages": 3 + } + } + """ diff --git a/test/corpus/main_test.go b/test/corpus/main_test.go new file mode 100644 index 00000000..345cc3ae --- /dev/null +++ b/test/corpus/main_test.go @@ -0,0 +1,13 @@ +//go:build corpus + +package corpus + +import ( + "testing" + + "github.com/gotenberg/gotenberg/v9/test/integration/scenario" +) + +func TestMain(_ *testing.M) { + scenario.RunSuite("corpus") +} diff --git a/test/integration/testdata/corpus/generators/README.md b/test/corpus/testdata/generators/README.md similarity index 83% rename from test/integration/testdata/corpus/generators/README.md rename to test/corpus/testdata/generators/README.md index 5f0f648c..6fb27609 100644 --- a/test/integration/testdata/corpus/generators/README.md +++ b/test/corpus/testdata/generators/README.md @@ -2,7 +2,7 @@ These scripts are the provenance of the corpus fixtures one directory up. Run them only to regenerate a fixture; the generated files are checked in. -Run them in this order, with `C` set to a scratch copy of the corpus root and `B` to a scratch directory. The font paths are macOS paths (`/System/Library/Fonts/Supplemental/Arial*.ttf`); change them on another system. +Run them in this order, with `C` set to a scratch copy of `testdata/` and `B` to a scratch directory. The font paths are macOS paths (`/System/Library/Fonts/Supplemental/Arial*.ttf`); change them on another system. ```bash export C=/tmp/corpus B=/tmp/corpus-build diff --git a/test/integration/testdata/corpus/generators/conv.sh b/test/corpus/testdata/generators/conv.sh similarity index 100% rename from test/integration/testdata/corpus/generators/conv.sh rename to test/corpus/testdata/generators/conv.sh diff --git a/test/integration/testdata/corpus/generators/i18n.json b/test/corpus/testdata/generators/i18n.json similarity index 100% rename from test/integration/testdata/corpus/generators/i18n.json rename to test/corpus/testdata/generators/i18n.json diff --git a/test/integration/testdata/corpus/generators/img_pdf.py b/test/corpus/testdata/generators/img_pdf.py similarity index 100% rename from test/integration/testdata/corpus/generators/img_pdf.py rename to test/corpus/testdata/generators/img_pdf.py diff --git a/test/integration/testdata/corpus/generators/office1.py b/test/corpus/testdata/generators/office1.py similarity index 100% rename from test/integration/testdata/corpus/generators/office1.py rename to test/corpus/testdata/generators/office1.py diff --git a/test/integration/testdata/corpus/generators/web.py b/test/corpus/testdata/generators/web.py similarity index 100% rename from test/integration/testdata/corpus/generators/web.py rename to test/corpus/testdata/generators/web.py diff --git a/test/integration/testdata/corpus/office/budget.xlsx b/test/corpus/testdata/office/budget.xlsx similarity index 100% rename from test/integration/testdata/corpus/office/budget.xlsx rename to test/corpus/testdata/office/budget.xlsx diff --git a/test/integration/testdata/corpus/office/contract.docx b/test/corpus/testdata/office/contract.docx similarity index 100% rename from test/integration/testdata/corpus/office/contract.docx rename to test/corpus/testdata/office/contract.docx diff --git a/test/integration/testdata/corpus/office/data.xml b/test/corpus/testdata/office/data.xml similarity index 100% rename from test/integration/testdata/corpus/office/data.xml rename to test/corpus/testdata/office/data.xml diff --git a/test/integration/testdata/corpus/office/deck.pptx b/test/corpus/testdata/office/deck.pptx similarity index 100% rename from test/integration/testdata/corpus/office/deck.pptx rename to test/corpus/testdata/office/deck.pptx diff --git a/test/integration/testdata/corpus/office/figures-lo.xlsx b/test/corpus/testdata/office/figures-lo.xlsx similarity index 100% rename from test/integration/testdata/corpus/office/figures-lo.xlsx rename to test/corpus/testdata/office/figures-lo.xlsx diff --git a/test/integration/testdata/corpus/office/figures.fods b/test/corpus/testdata/office/figures.fods similarity index 100% rename from test/integration/testdata/corpus/office/figures.fods rename to test/corpus/testdata/office/figures.fods diff --git a/test/integration/testdata/corpus/office/figures.ods b/test/corpus/testdata/office/figures.ods similarity index 100% rename from test/integration/testdata/corpus/office/figures.ods rename to test/corpus/testdata/office/figures.ods diff --git a/test/integration/testdata/corpus/office/figures.xls b/test/corpus/testdata/office/figures.xls similarity index 100% rename from test/integration/testdata/corpus/office/figures.xls rename to test/corpus/testdata/office/figures.xls diff --git a/test/integration/testdata/corpus/office/form.fodt b/test/corpus/testdata/office/form.fodt similarity index 100% rename from test/integration/testdata/corpus/office/form.fodt rename to test/corpus/testdata/office/form.fodt diff --git a/test/integration/testdata/corpus/office/form.odt b/test/corpus/testdata/office/form.odt similarity index 100% rename from test/integration/testdata/corpus/office/form.odt rename to test/corpus/testdata/office/form.odt diff --git a/test/integration/testdata/corpus/office/i18n.docx b/test/corpus/testdata/office/i18n.docx similarity index 100% rename from test/integration/testdata/corpus/office/i18n.docx rename to test/corpus/testdata/office/i18n.docx diff --git a/test/integration/testdata/corpus/office/images/diagram.png b/test/corpus/testdata/office/images/diagram.png similarity index 100% rename from test/integration/testdata/corpus/office/images/diagram.png rename to test/corpus/testdata/office/images/diagram.png diff --git a/test/integration/testdata/corpus/office/images/icon.gif b/test/corpus/testdata/office/images/icon.gif similarity index 100% rename from test/integration/testdata/corpus/office/images/icon.gif rename to test/corpus/testdata/office/images/icon.gif diff --git a/test/integration/testdata/corpus/office/images/logo.svg b/test/corpus/testdata/office/images/logo.svg similarity index 100% rename from test/integration/testdata/corpus/office/images/logo.svg rename to test/corpus/testdata/office/images/logo.svg diff --git a/test/integration/testdata/corpus/office/images/photo.jpg b/test/corpus/testdata/office/images/photo.jpg similarity index 100% rename from test/integration/testdata/corpus/office/images/photo.jpg rename to test/corpus/testdata/office/images/photo.jpg diff --git a/test/integration/testdata/corpus/office/images/pic.bmp b/test/corpus/testdata/office/images/pic.bmp similarity index 100% rename from test/integration/testdata/corpus/office/images/pic.bmp rename to test/corpus/testdata/office/images/pic.bmp diff --git a/test/integration/testdata/corpus/office/images/pic.webp b/test/corpus/testdata/office/images/pic.webp similarity index 100% rename from test/integration/testdata/corpus/office/images/pic.webp rename to test/corpus/testdata/office/images/pic.webp diff --git a/test/integration/testdata/corpus/office/images/scan.tif b/test/corpus/testdata/office/images/scan.tif similarity index 100% rename from test/integration/testdata/corpus/office/images/scan.tif rename to test/corpus/testdata/office/images/scan.tif diff --git a/test/integration/testdata/corpus/office/letter.rtf b/test/corpus/testdata/office/letter.rtf similarity index 100% rename from test/integration/testdata/corpus/office/letter.rtf rename to test/corpus/testdata/office/letter.rtf diff --git a/test/integration/testdata/corpus/office/memo-lo.docx b/test/corpus/testdata/office/memo-lo.docx similarity index 100% rename from test/integration/testdata/corpus/office/memo-lo.docx rename to test/corpus/testdata/office/memo-lo.docx diff --git a/test/integration/testdata/corpus/office/memo.doc b/test/corpus/testdata/office/memo.doc similarity index 100% rename from test/integration/testdata/corpus/office/memo.doc rename to test/corpus/testdata/office/memo.doc diff --git a/test/integration/testdata/corpus/office/memo.fodt b/test/corpus/testdata/office/memo.fodt similarity index 100% rename from test/integration/testdata/corpus/office/memo.fodt rename to test/corpus/testdata/office/memo.fodt diff --git a/test/integration/testdata/corpus/office/memo.html b/test/corpus/testdata/office/memo.html similarity index 100% rename from test/integration/testdata/corpus/office/memo.html rename to test/corpus/testdata/office/memo.html diff --git a/test/integration/testdata/corpus/office/memo.odt b/test/corpus/testdata/office/memo.odt similarity index 100% rename from test/integration/testdata/corpus/office/memo.odt rename to test/corpus/testdata/office/memo.odt diff --git a/test/integration/testdata/corpus/office/memo.pdf b/test/corpus/testdata/office/memo.pdf similarity index 100% rename from test/integration/testdata/corpus/office/memo.pdf rename to test/corpus/testdata/office/memo.pdf diff --git a/test/integration/testdata/corpus/office/memo.rtf b/test/corpus/testdata/office/memo.rtf similarity index 100% rename from test/integration/testdata/corpus/office/memo.rtf rename to test/corpus/testdata/office/memo.rtf diff --git a/test/integration/testdata/corpus/office/page.htm b/test/corpus/testdata/office/page.htm similarity index 100% rename from test/integration/testdata/corpus/office/page.htm rename to test/corpus/testdata/office/page.htm diff --git a/test/integration/testdata/corpus/office/pitch-lo.pptx b/test/corpus/testdata/office/pitch-lo.pptx similarity index 100% rename from test/integration/testdata/corpus/office/pitch-lo.pptx rename to test/corpus/testdata/office/pitch-lo.pptx diff --git a/test/integration/testdata/corpus/office/pitch.fodp b/test/corpus/testdata/office/pitch.fodp similarity index 100% rename from test/integration/testdata/corpus/office/pitch.fodp rename to test/corpus/testdata/office/pitch.fodp diff --git a/test/integration/testdata/corpus/office/pitch.odp b/test/corpus/testdata/office/pitch.odp similarity index 100% rename from test/integration/testdata/corpus/office/pitch.odp rename to test/corpus/testdata/office/pitch.odp diff --git a/test/integration/testdata/corpus/office/pitch.ppt b/test/corpus/testdata/office/pitch.ppt similarity index 100% rename from test/integration/testdata/corpus/office/pitch.ppt rename to test/corpus/testdata/office/pitch.ppt diff --git a/test/integration/testdata/corpus/office/readme.txt b/test/corpus/testdata/office/readme.txt similarity index 100% rename from test/integration/testdata/corpus/office/readme.txt rename to test/corpus/testdata/office/readme.txt diff --git a/test/integration/testdata/corpus/office/sales.csv b/test/corpus/testdata/office/sales.csv similarity index 100% rename from test/integration/testdata/corpus/office/sales.csv rename to test/corpus/testdata/office/sales.csv diff --git a/test/integration/testdata/corpus/office/tracked.docx b/test/corpus/testdata/office/tracked.docx similarity index 100% rename from test/integration/testdata/corpus/office/tracked.docx rename to test/corpus/testdata/office/tracked.docx diff --git a/test/integration/testdata/corpus/pdf/annex.pdf b/test/corpus/testdata/pdf/annex.pdf similarity index 100% rename from test/integration/testdata/corpus/pdf/annex.pdf rename to test/corpus/testdata/pdf/annex.pdf diff --git a/test/integration/testdata/corpus/pdf/attachment.csv b/test/corpus/testdata/pdf/attachment.csv similarity index 100% rename from test/integration/testdata/corpus/pdf/attachment.csv rename to test/corpus/testdata/pdf/attachment.csv diff --git a/test/integration/testdata/corpus/pdf/black.png b/test/corpus/testdata/pdf/black.png similarity index 100% rename from test/integration/testdata/corpus/pdf/black.png rename to test/corpus/testdata/pdf/black.png diff --git a/test/integration/testdata/corpus/pdf/cert.p12 b/test/corpus/testdata/pdf/cert.p12 similarity index 100% rename from test/integration/testdata/corpus/pdf/cert.p12 rename to test/corpus/testdata/pdf/cert.p12 diff --git a/test/integration/testdata/corpus/pdf/colors.pdf b/test/corpus/testdata/pdf/colors.pdf similarity index 100% rename from test/integration/testdata/corpus/pdf/colors.pdf rename to test/corpus/testdata/pdf/colors.pdf diff --git a/test/integration/testdata/corpus/pdf/encrypted-rc4.pdf b/test/corpus/testdata/pdf/encrypted-rc4.pdf similarity index 100% rename from test/integration/testdata/corpus/pdf/encrypted-rc4.pdf rename to test/corpus/testdata/pdf/encrypted-rc4.pdf diff --git a/test/integration/testdata/corpus/pdf/encrypted.pdf b/test/corpus/testdata/pdf/encrypted.pdf similarity index 100% rename from test/integration/testdata/corpus/pdf/encrypted.pdf rename to test/corpus/testdata/pdf/encrypted.pdf diff --git a/test/integration/testdata/corpus/pdf/image-heavy.pdf b/test/corpus/testdata/pdf/image-heavy.pdf similarity index 100% rename from test/integration/testdata/corpus/pdf/image-heavy.pdf rename to test/corpus/testdata/pdf/image-heavy.pdf diff --git a/test/integration/testdata/corpus/pdf/invoice-cii.xml b/test/corpus/testdata/pdf/invoice-cii.xml similarity index 100% rename from test/integration/testdata/corpus/pdf/invoice-cii.xml rename to test/corpus/testdata/pdf/invoice-cii.xml diff --git a/test/integration/testdata/corpus/pdf/letterhead.pdf b/test/corpus/testdata/pdf/letterhead.pdf similarity index 100% rename from test/integration/testdata/corpus/pdf/letterhead.pdf rename to test/corpus/testdata/pdf/letterhead.pdf diff --git a/test/integration/testdata/corpus/pdf/report.pdf b/test/corpus/testdata/pdf/report.pdf similarity index 100% rename from test/integration/testdata/corpus/pdf/report.pdf rename to test/corpus/testdata/pdf/report.pdf diff --git a/test/integration/testdata/corpus/pdf/stamp.jpg b/test/corpus/testdata/pdf/stamp.jpg similarity index 100% rename from test/integration/testdata/corpus/pdf/stamp.jpg rename to test/corpus/testdata/pdf/stamp.jpg diff --git a/test/integration/testdata/corpus/pdf/transparent.pdf b/test/corpus/testdata/pdf/transparent.pdf similarity index 100% rename from test/integration/testdata/corpus/pdf/transparent.pdf rename to test/corpus/testdata/pdf/transparent.pdf diff --git a/test/integration/testdata/corpus/web/console-error/index.html b/test/corpus/testdata/web/console-error/index.html similarity index 100% rename from test/integration/testdata/corpus/web/console-error/index.html rename to test/corpus/testdata/web/console-error/index.html diff --git a/test/integration/testdata/corpus/web/i18n/index.html b/test/corpus/testdata/web/i18n/index.html similarity index 100% rename from test/integration/testdata/corpus/web/i18n/index.html rename to test/corpus/testdata/web/i18n/index.html diff --git a/test/integration/testdata/corpus/web/invoice/footer.html b/test/corpus/testdata/web/invoice/footer.html similarity index 100% rename from test/integration/testdata/corpus/web/invoice/footer.html rename to test/corpus/testdata/web/invoice/footer.html diff --git a/test/integration/testdata/corpus/web/invoice/header.html b/test/corpus/testdata/web/invoice/header.html similarity index 100% rename from test/integration/testdata/corpus/web/invoice/header.html rename to test/corpus/testdata/web/invoice/header.html diff --git a/test/integration/testdata/corpus/web/invoice/index.html b/test/corpus/testdata/web/invoice/index.html similarity index 100% rename from test/integration/testdata/corpus/web/invoice/index.html rename to test/corpus/testdata/web/invoice/index.html diff --git a/test/integration/testdata/corpus/web/invoice/logo.png b/test/corpus/testdata/web/invoice/logo.png similarity index 100% rename from test/integration/testdata/corpus/web/invoice/logo.png rename to test/corpus/testdata/web/invoice/logo.png diff --git a/test/integration/testdata/corpus/web/invoice/style.css b/test/corpus/testdata/web/invoice/style.css similarity index 100% rename from test/integration/testdata/corpus/web/invoice/style.css rename to test/corpus/testdata/web/invoice/style.css diff --git a/test/integration/testdata/corpus/web/landing/index.html b/test/corpus/testdata/web/landing/index.html similarity index 100% rename from test/integration/testdata/corpus/web/landing/index.html rename to test/corpus/testdata/web/landing/index.html diff --git a/test/integration/testdata/corpus/web/markdown/changelog.md b/test/corpus/testdata/web/markdown/changelog.md similarity index 100% rename from test/integration/testdata/corpus/web/markdown/changelog.md rename to test/corpus/testdata/web/markdown/changelog.md diff --git a/test/integration/testdata/corpus/web/markdown/index.html b/test/corpus/testdata/web/markdown/index.html similarity index 100% rename from test/integration/testdata/corpus/web/markdown/index.html rename to test/corpus/testdata/web/markdown/index.html diff --git a/test/integration/testdata/corpus/web/markdown/release-notes.md b/test/corpus/testdata/web/markdown/release-notes.md similarity index 100% rename from test/integration/testdata/corpus/web/markdown/release-notes.md rename to test/corpus/testdata/web/markdown/release-notes.md diff --git a/test/integration/testdata/corpus/web/markdown/screenshot.png b/test/corpus/testdata/web/markdown/screenshot.png similarity index 100% rename from test/integration/testdata/corpus/web/markdown/screenshot.png rename to test/corpus/testdata/web/markdown/screenshot.png diff --git a/test/integration/testdata/corpus/web/markdown/style.css b/test/corpus/testdata/web/markdown/style.css similarity index 100% rename from test/integration/testdata/corpus/web/markdown/style.css rename to test/corpus/testdata/web/markdown/style.css diff --git a/test/integration/testdata/corpus/web/print-css/index.html b/test/corpus/testdata/web/print-css/index.html similarity index 100% rename from test/integration/testdata/corpus/web/print-css/index.html rename to test/corpus/testdata/web/print-css/index.html diff --git a/test/integration/testdata/corpus/web/print-css/print.css b/test/corpus/testdata/web/print-css/print.css similarity index 100% rename from test/integration/testdata/corpus/web/print-css/print.css rename to test/corpus/testdata/web/print-css/print.css diff --git a/test/integration/testdata/corpus/web/site.zip b/test/corpus/testdata/web/site.zip similarity index 100% rename from test/integration/testdata/corpus/web/site.zip rename to test/corpus/testdata/web/site.zip diff --git a/test/integration/testdata/corpus/web/wait/index.html b/test/corpus/testdata/web/wait/index.html similarity index 100% rename from test/integration/testdata/corpus/web/wait/index.html rename to test/corpus/testdata/web/wait/index.html diff --git a/test/integration/testdata/corpus/web/wide-table/index.html b/test/corpus/testdata/web/wide-table/index.html similarity index 100% rename from test/integration/testdata/corpus/web/wide-table/index.html rename to test/corpus/testdata/web/wide-table/index.html diff --git a/test/integration/README.md b/test/integration/README.md index 8d98a7fe..2fcd74e6 100644 --- a/test/integration/README.md +++ b/test/integration/README.md @@ -5,7 +5,7 @@ Gherkin (BDD) via [Godog](https://github.com/cucumber/godog), with `testcontaine - Feature files: `test/integration/features/*.feature`, one per endpoint or capability. - Step definitions: `test/integration/scenario/` (container management, HTTP helpers, PDF validation). - Entry point: `test/integration/main_test.go` (build tag: `integration`). -- Test data: `test/integration/testdata/`. The release QA corpus sits in `testdata/corpus/` and backs `corpus.feature`: its [`README.md`](testdata/corpus/README.md) says why it exists and how to extend it, its `MANIFEST.md` what each file contains. +- Test data: `test/integration/testdata/`, the fixtures of these scenarios. A file that exists to exercise one field belongs here; a document that stands for a real user file, with its facts in a manifest, belongs in `test/corpus/testdata/`. See the [corpus suite](../corpus/README.md). Each scenario spins up a fresh Gotenberg Docker container via testcontainers. The PDF assertions read the produced documents with [litho](https://github.com/gotenberg/litho), in process: page count, size, text, tagging, bookmarks, metadata, attachments, permissions, signatures, and PDF/A and PDF/UA conformance. @@ -31,7 +31,6 @@ Available tags: | Chromium | `chromium`, `chromium-concurrent`, `chromium-convert-html`, `chromium-image-deduplication`, `chromium-convert-markdown`, `chromium-convert-url`, `chromium-screenshot-html`, `chromium-screenshot-markdown`, `chromium-screenshot-url`, `chromium-ssrf` | | LibreOffice | `libreoffice`, `libreoffice-convert`, `libreoffice-ssrf` | | PDF | `pdf`, `pdf-pipe`, `pdf-merge`, `pdf-split`, `pdf-pages`, `pdf-rotate`, `pdf-stamp`, `pdf-metadata`, `pdf-bookmarks`, `pdf-form`, `pdf-attach`, `pdf-encrypt`, `pdf-remediate`, `factur-x`, `pdf-sign`, `pdf-optimize`, `pdf-redact`, `pdf-colors`, `pdf-render`, `pdf-read` | -| Corpus | `corpus`, `corpus-chromium`, `corpus-libreoffice`, `corpus-pdf` | | Infra | `health`, `debug`, `root`, `version`, `output-filename`, `webhook`, `download-from`, `api-limits`, `api-archives` | ## Writing a new test diff --git a/test/integration/features/corpus.feature b/test/integration/features/corpus.feature deleted file mode 100644 index 9a1a3273..00000000 --- a/test/integration/features/corpus.feature +++ /dev/null @@ -1,831 +0,0 @@ -@corpus -Feature: Release QA corpus - Realistic documents with known contents, described in testdata/corpus/MANIFEST.md. - - # The page break comes from the CSS (`break-before: page` on the payment terms heading) and - # the size from `@page { size: A4 }`. - @corpus-chromium - Scenario: Invoice site (2 A4 pages) - 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/corpus/web/invoice/index.html | file | - | files | testdata/corpus/web/invoice/style.css | file | - | files | testdata/corpus/web/invoice/logo.png | file | - | files | testdata/corpus/web/invoice/header.html | file | - | files | testdata/corpus/web/invoice/footer.html | file | - | preferCssPageSize | true | field | - | printBackground | true | field | - | nativeBookmarks | true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 2 page(s) - Then the "foo.pdf" PDF page 1 should be 595.28x841.89 points - Then the "foo.pdf" PDF page 2 should be 595.28x841.89 points - Then the "foo.pdf" PDF should have the "Title" metadata set to "Invoice INV-2026-0042" - Then the "foo.pdf" PDF should have a document outline - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Northwind Traders - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Contoso Ltd - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - 4,620.00 EUR - """ - Then the "foo.pdf" PDF should NOT have the following content at page 1: - """ - Payment terms - """ - Then the "foo.pdf" PDF should have content matching "Page\s*1\s*of\s*2" at page 1 - Then the "foo.pdf" PDF should have content matching "Page\s*2\s*of\s*2" at page 2 - Then the "foo.pdf" PDF should have the following content at page 2: - """ - Payment terms - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - IBAN FR76 3000 6000 0112 3456 7890 189 - """ - - @corpus-chromium - Scenario: Invoice site from a ZIP archive - 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): - | archives | testdata/corpus/web/site.zip | file | - | preferCssPageSize | true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 2 page(s) - Then the "foo.pdf" PDF page 1 should be 595.28x841.89 points - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Invoice INV-2026-0042 - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - IBAN FR76 3000 6000 0112 3456 7890 189 - """ - - @corpus-chromium - Scenario: Delayed content waits for an expression - 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/corpus/web/wait/index.html | file | - | waitForExpression | window.chartReady === true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Revenue: 42,000 EUR - """ - Then the "foo.pdf" PDF should NOT have the following content at page 1: - """ - Loading - """ - - # The exception happens after the render: the page converts unless the flag is set. - @corpus-chromium - Scenario: A console exception fails the conversion - 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/corpus/web/console-error/index.html | file | - | failOnConsoleExceptions | true | field | - Then the response status code should be 409 - Then the response body should contain string: - """ - Chromium console exceptions - """ - 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/corpus/web/console-error/index.html | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Console error page - """ - - # The inline script sets the title to "pwned" if it runs. The title stays the one of the - # template and the text right after the script survives. - @corpus-chromium - Scenario: Markdown bundle keeps the text and the title - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/markdown" endpoint with the following form data and header(s): - | files | testdata/corpus/web/markdown/index.html | file | - | files | testdata/corpus/web/markdown/release-notes.md | file | - | files | testdata/corpus/web/markdown/changelog.md | file | - | files | testdata/corpus/web/markdown/style.css | file | - | files | testdata/corpus/web/markdown/screenshot.png | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have the "Title" metadata set to "Release notes 9.0.0" - Then the "foo.pdf" PDF should have 2 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Release notes 9.0.0 - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - CODE-BLOCK-MARKER - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - DONE-TASK - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - OPEN-TASK - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Removed legacy flag - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - SANITIZE-ME-MARKER - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - CHANGELOG-V9 - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - CHANGELOG-V8 - """ - Then the "foo.pdf" PDF should have 1 image(s) - - # The navigation is hidden in print, and a block shows only from a 1200 px viewport. - @corpus-chromium - Scenario: Landing page: print media and viewport width - 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/corpus/web/landing/index.html | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Start free trial - """ - Then the "foo.pdf" PDF should NOT have the following content at page 1: - """ - Pricing - """ - Then the "foo.pdf" PDF should NOT have the following content at page 1: - """ - WIDE-LAYOUT-MARKER - """ - 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/corpus/web/landing/index.html | file | - | paperWidth | 14 | field | - | paperHeight | 11 | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have the following content at page 1: - """ - WIDE-LAYOUT-MARKER - """ - 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/corpus/web/landing/index.html | file | - | singlePage | true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Start free trial - """ - - # The Latin marker of a right-to-left line can come out as ":AR": the patterns accept both. - @corpus-chromium - Scenario: Multilingual page renders every script - 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/corpus/web/i18n/index.html | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Multilingual - """ - Then the "foo.pdf" PDF should have content matching "AR:|:AR" at page 1 - Then the "foo.pdf" PDF should have content matching "HE:|:HE" at page 1 - Then the "foo.pdf" PDF should have content matching "ZH:|:ZH" at page 1 - Then the "foo.pdf" PDF should have content matching "JA:|:JA" at page 1 - Then the "foo.pdf" PDF should have content matching "KO:|:KO" at page 1 - Then the "foo.pdf" PDF should have content matching "TH:|:TH" at page 1 - Then the "foo.pdf" PDF should have content matching "HI:|:HI" at page 1 - Then the "foo.pdf" PDF should have content matching "EL:|:EL" at page 1 - Then the "foo.pdf" PDF should have content matching "RU:|:RU" at page 1 - Then the "foo.pdf" PDF should have content matching "EMOJI:|:EMOJI" at page 1 - Then the "foo.pdf" PDF should have content matching "MATH:|:MATH" at page 1 - - @corpus-chromium - Scenario: Print CSS handbook gives A5 pages - 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/corpus/web/print-css/index.html | file | - | files | testdata/corpus/web/print-css/print.css | file | - | preferCssPageSize | true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 4 page(s) - Then the "foo.pdf" PDF page 1 should be 419.53x595.28 points - Then the "foo.pdf" PDF page 4 should be 419.53x595.28 points - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Handbook - """ - Then the "foo.pdf" PDF should NOT have the following content at page 1: - """ - NAV-MARKER - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - CHAPTER-ONE - """ - Then the "foo.pdf" PDF should have the following content at page 3: - """ - CHAPTER-TWO - """ - Then the "foo.pdf" PDF should have the following content at page 4: - """ - CHAPTER-THREE - """ - - @corpus-chromium - Scenario: Wide table on a single page - 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/corpus/web/wide-table/index.html | file | - | singlePage | true | field | - | landscape | true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the "Title" metadata set to "Wide table" - Then the "foo.pdf" PDF should have the following content at page 1: - """ - C01 - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - r40c30 - """ - - @corpus-libreoffice - Scenario: Contract DOCX (10 pages) - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/contract.docx | file | - | nativeBookmarks | true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 10 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Master Services Agreement - """ - Then the "foo.pdf" PDF should have the following content at page 10: - """ - Schedule A - """ - Then the "foo.pdf" PDF should NOT have the following content at page 1: - """ - Schedule A - """ - Then the "foo.pdf" PDF should have the "Title" metadata set to "Master Services Agreement" - Then the "foo.pdf" PDF should have the "Author" metadata set to "Legal Department" - Then the "foo.pdf" PDF should have the "Subject" metadata set to "Services" - Then the "foo.pdf" PDF should have the "Keywords" metadata set to "contract, msa" - Then the "foo.pdf" PDF should have a document outline - Then the "foo.pdf" PDF should have content matching "Page" at page 1 - - # The first column clips long cells ("Cloud host"). The Monthly sheet spans two pages; `singlePage` fits each sheet on one page. - @corpus-libreoffice - Scenario: Budget XLSX (3 sheets) - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/budget.xlsx | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 4 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - FY2026 Budget - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Cloud host - """ - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/budget.xlsx | file | - | singlePage | true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - FY2026 Budget - """ - Then the "foo.pdf" PDF should have the following content at page 3: - """ - Budget not - """ - Then the "foo.pdf" PDF should have the following content at page 3: - """ - Prepared - """ - - @corpus-libreoffice - Scenario: Deck PPTX without the hidden slide, then with notes pages - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/deck.pptx | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 7 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Q4 Product Review - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - Agenda - """ - Then the "foo.pdf" PDF should have the following content at page 4: - """ - R2C2 - """ - Then the "foo.pdf" PDF should have the following content at page 7: - """ - Thank you - """ - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 1 - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 2 - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 3 - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 4 - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 5 - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 6 - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 7 - Then the "foo.pdf" PDF should NOT have content matching "NOTES-MARKER" at page 2 - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/deck.pptx | file | - | exportNotesPages | true | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 14 page(s) - Then the "foo.pdf" PDF should have the following content at page 9: - """ - NOTES-MARKER-2 - """ - Then the "foo.pdf" PDF should have the following content at page 14: - """ - NOTES-MARKER-8 - """ - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 7 - Then the "foo.pdf" PDF should NOT have content matching "HIDDEN-SLIDE-MARKER" at page 13 - - # Fails until lok passes the CSV import options: every line lands in one cell today. - @corpus-libreoffice - Scenario: CSV keeps its columns - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/sales.csv | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have the following content at page 1: - """ - customer - """ - Then the "foo.pdf" PDF should NOT have the following content at page 1: - """ - id,date,customer - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Café Müller - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Straße GmbH - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Élodie & Fils - """ - - @corpus-libreoffice - Scenario: Tracked changes keep the inserted text - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/tracked.docx | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - INSERTED-TEXT - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - End of sentence. - """ - - @corpus-libreoffice - Scenario: Multilingual DOCX - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/i18n.docx | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Multilingual document - """ - Then the "foo.pdf" PDF should have content matching "AR:|:AR" at page 1 - Then the "foo.pdf" PDF should have content matching "HE:|:HE" at page 1 - Then the "foo.pdf" PDF should have content matching "ZH:|:ZH" at page 1 - Then the "foo.pdf" PDF should have content matching "JA:|:JA" at page 1 - Then the "foo.pdf" PDF should have content matching "KO:|:KO" at page 1 - Then the "foo.pdf" PDF should have content matching "TH:|:TH" at page 1 - Then the "foo.pdf" PDF should have content matching "HI:|:HI" at page 1 - Then the "foo.pdf" PDF should have content matching "EL:|:EL" at page 1 - Then the "foo.pdf" PDF should have content matching "RU:|:RU" at page 1 - Then the "foo.pdf" PDF should have content matching "EMOJI:|:EMOJI" at page 1 - Then the "foo.pdf" PDF should have content matching "MATH:|:MATH" at page 1 - - @corpus-libreoffice - Scenario: Form ODT keeps its text - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/form.odt | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - FORM-DOC-MARKER - """ - - # The manifest counted 3 pages with another LibreOffice build; the image gives 4. - @corpus-libreoffice - Scenario: Plain text paginates - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/readme.txt | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 4 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Line 01: - """ - Then the "foo.pdf" PDF should have the following content at page 4: - """ - Line 60: - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Café résumé naïve déjà vu - """ - - @corpus-libreoffice - Scenario: WebP is not an accepted input - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/images/pic.webp | file | - Then the response status code should be 400 - Then the response body should contain string: - """ - Invalid form data: no form file found for extensions: - """ - - @corpus-libreoffice - Scenario Outline: Office formats convert with the documented pages and text - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/ | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have page(s) - Then the "foo.pdf" PDF should have the following content at page : - """ - - """ - - Examples: - | file | pages | page | marker | - | memo.fodt | 1 | 1 | MEMO-END-MARKER | - | memo.odt | 1 | 1 | MEMO-END-MARKER | - | memo.doc | 1 | 1 | MEMO-END-MARKER | - | memo.rtf | 1 | 1 | MEMO-END-MARKER | - | memo-lo.docx | 1 | 1 | MEMO-END-MARKER | - | memo.html | 1 | 1 | MEMO-END-MARKER | - | memo.pdf | 1 | 1 | MEMO-END-MARKER | - | figures.fods | 2 | 1 | REVENUE-SH | - | figures.fods | 2 | 2 | COSTS-SHEE | - | figures.ods | 2 | 1 | REVENUE-SH | - | figures.ods | 2 | 2 | COSTS-SHEE | - | figures.xls | 2 | 1 | REVENUE-SH | - | figures.xls | 2 | 2 | COSTS-SHEE | - | figures-lo.xlsx | 2 | 1 | REVENUE-SH | - | figures-lo.xlsx | 2 | 2 | COSTS-SHEE | - | pitch.fodp | 4 | 1 | PITCH-1 | - | pitch.fodp | 4 | 4 | PITCH-4 | - | pitch.odp | 4 | 1 | PITCH-1 | - | pitch.odp | 4 | 4 | PITCH-4 | - | pitch.ppt | 4 | 1 | PITCH-1 | - | pitch.ppt | 4 | 4 | PITCH-4 | - | pitch-lo.pptx | 4 | 1 | PITCH-1 | - | pitch-lo.pptx | 4 | 4 | PITCH-4 | - | letter.rtf | 1 | 1 | Northwind Traders | - | letter.rtf | 1 | 1 | Second item | - | page.htm | 1 | 1 | HTM-MARKER | - | data.xml | 1 | 1 | XML-MARKER | - | data.xml | 1 | 1 | Second | - - @corpus-libreoffice - Scenario Outline: Image formats convert to a one-page PDF - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/images/ | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - 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) - - Examples: - | file | - | photo.jpg | - | diagram.png | - | icon.gif | - | scan.tif | - | pic.bmp | - - @corpus-libreoffice - Scenario: SVG converts to a one-page PDF - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s): - | files | testdata/corpus/office/images/logo.svg | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - - @corpus-pdf - Scenario: Report PDF: info and metadata - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - Then the response status code should be 200 - Then the response body should match JSON: - """ - { - "report.pdf": { - "pages": 3, - "version": "ignore", - "encrypted": false, - "tagged": false, - "linearized": false, - "formFields": false - } - } - """ - When I make a "POST" request to Gotenberg at the "/forms/pdf/metadata" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - Then the response status code should be 200 - Then the response body should match JSON: - """ - { - "report.pdf": { - "title": "Quarterly Report", - "author": "Finance" - } - } - """ - When I make a "POST" request to Gotenberg at the "/forms/pdf/merge" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF page 1 should be 612x792 points - Then the "foo.pdf" PDF page 3 should be 612x792 points - Then the "foo.pdf" PDF should have the "Title" metadata set to "Quarterly Report" - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Body line 1 of page 1 - """ - Then the "foo.pdf" PDF should have the following content at page 3: - """ - REPORT-PAGE-3 - """ - - @corpus-pdf - Scenario: Redaction removes the label of page 1 only - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/redact" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - | regions | [{"page":1,"x":70,"y":388,"width":300,"height":42}] | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF should NOT have the following content at page 1: - """ - REPORT-PAGE-1 - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Quarterly Report - """ - Then the "foo.pdf" PDF should have the following content at page 1: - """ - Body line 1 of page 1 - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - REPORT-PAGE-2 - """ - Then the "foo.pdf" PDF should have the following content at page 3: - """ - REPORT-PAGE-3 - """ - Then the "foo.pdf" PDF page 1 should be 612x792 points - - # Inputs merge in the order of their filenames, so the annex comes first. - @corpus-pdf - Scenario: Merge report and annex - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/merge" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - | files | testdata/corpus/pdf/annex.pdf | file | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 5 page(s) - Then the "foo.pdf" PDF page 5 should be 612x792 points - Then the "foo.pdf" PDF should have the following content at page 1: - """ - ANNEX-PAGE-1 - """ - Then the "foo.pdf" PDF should have the following content at page 2: - """ - ANNEX-PAGE-2 - """ - Then the "foo.pdf" PDF should have the following content at page 3: - """ - REPORT-PAGE-1 - """ - Then the "foo.pdf" PDF should have the following content at page 4: - """ - REPORT-PAGE-2 - """ - Then the "foo.pdf" PDF should have the following content at page 5: - """ - REPORT-PAGE-3 - """ - - @corpus-pdf - Scenario: Stamp text and image - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/stamp-text" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - | text | APPROVED-STAMP | field | - | pages | 1 | field | - | x | 72 | field | - | y | 200 | field | - | fontSize | 24 | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - REPORT-PAGE-1 - """ - When I make a "POST" request to Gotenberg at the "/forms/pdf/stamp-image" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - | files | testdata/corpus/pdf/stamp.jpg | file | - | image | stamp.jpg | field | - | pages | 1 | field | - | width | 150 | field | - | height | 50 | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF should have 1 image(s) - - @corpus-pdf - Scenario: Letterhead stamped under the report - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/stamp-pdf" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - | files | testdata/corpus/pdf/letterhead.pdf | file | - | source | letterhead.pdf | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - REPORT-PAGE-1 - """ - - @corpus-pdf - Scenario: Encrypted PDF needs its password - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/encrypted.pdf | file | - Then the response status code should be 400 - When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/encrypted.pdf | file | - | password | secret | field | - Then the response status code should be 200 - Then the response body should match JSON: - """ - { - "encrypted.pdf": { - "pages": 3, - "encrypted": true - } - } - """ - When I make a "POST" request to Gotenberg at the "/forms/pdf/decrypt" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/encrypted.pdf | file | - Then the response status code should be 400 - When I make a "POST" request to Gotenberg at the "/forms/pdf/decrypt" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/encrypted.pdf | file | - | password | secret | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the response PDF(s) should NOT be encrypted - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF should have the following content at page 3: - """ - REPORT-PAGE-3 - """ - When I make a "POST" request to Gotenberg at the "/forms/pdf/decrypt" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/encrypted-rc4.pdf | file | - | password | secret | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the response PDF(s) should NOT be encrypted - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF should have the following content at page 2: - """ - REPORT-PAGE-2 - """ - - @corpus-pdf - Scenario: Factur-X embeds the CII invoice - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/remediate" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/report.pdf | file | - | files | testdata/corpus/pdf/invoice-cii.xml | file | - | profile | Factur-X | field | - | xml | invoice-cii.xml | field | - | level | EN 16931 | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the response header "Gotenberg-Remediation-Residual" should be "0" - Then the "foo.pdf" PDF should have 3 page(s) - Then the "foo.pdf" PDF should have the "Title" metadata set to "Quarterly Report" - Then the response PDF(s) should be valid "PDF/A-3b" with a tolerance of 0 failed rule(s) - Then the response PDF(s) should have the "factur-x.xml" file embedded with relationship "Alternative" - Then the response PDF(s) should declare Factur-X XMP with conformance level "EN 16931" - - @corpus-pdf - Scenario: Transparency remediates to PDF/A-2b - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/remediate" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/transparent.pdf | file | - | profile | PDF/A-2b | field | - | Gotenberg-Output-Filename | foo | header | - Then the response status code should be 200 - Then the "foo.pdf" PDF should have 1 page(s) - Then the "foo.pdf" PDF should have the following content at page 1: - """ - TRANSPARENT-MARKER - """ - Then the response PDF(s) should be valid "PDF/A-2b" with a tolerance of 0 failed rule(s) - - @corpus-pdf - Scenario: Color and image-heavy samples read back - Given I have a default Gotenberg container - When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s): - | files | testdata/corpus/pdf/colors.pdf | file | - | files | testdata/corpus/pdf/image-heavy.pdf | file | - Then the response status code should be 200 - Then the response body should match JSON: - """ - { - "colors.pdf": { - "pages": 1 - }, - "image-heavy.pdf": { - "pages": 3 - } - } - """ diff --git a/test/integration/main_test.go b/test/integration/main_test.go index 897731ad..b3751f1e 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -3,164 +3,11 @@ package integration import ( - "context" - "fmt" - "os" - "os/signal" - "runtime" - "slices" - "strings" - "syscall" "testing" - "time" - - "github.com/cucumber/godog" - "github.com/cucumber/godog/colors" - flag "github.com/spf13/pflag" "github.com/gotenberg/gotenberg/v9/test/integration/scenario" ) -// runTimeout bounds a whole run, retries included. It stays below the go test -// timeout of the Makefile. -const runTimeout = 38 * time.Minute - -func TestMain(m *testing.M) { - repository := flag.String("gotenberg-docker-repository", "", "") - version := flag.String("gotenberg-version", "", "") - variant := flag.String("gotenberg-variant", "", "") - platform := flag.String("gotenberg-container-platform", "", "") - concurrencyFlag := flag.Int("concurrency", 0, "") - tags := flag.String("tags", "", "") - keepFailed := flag.String("keep-failed", "", "") - flag.Parse() - - if *platform == "" { - switch runtime.GOARCH { - case "arm64": - *platform = "linux/arm64" - default: - *platform = "linux/amd64" - } - } - - scenario.GotenbergDockerRepository = *repository - scenario.GotenbergVersion = *version - scenario.GotenbergVariant = *variant - scenario.GotenbergContainerPlatform = *platform - scenario.KeepFailedDir = *keepFailed - - concurrency := *concurrencyFlag - if concurrency <= 0 { - concurrency = runtime.NumCPU() - } - - maxAttempts := 4 // 1 initial run + up to 3 retries - paths := []string{"features"} - - // Steps run on this context: a step that waits on it fails before the go - // test timeout (-timeout 40m in the Makefile) panics, which would skip the - // retries and the report. - timeoutCtx, cancelTimeout := context.WithTimeout(context.Background(), runTimeout) - defer cancelTimeout() - - // An interrupt cancels the steps, then the run cleans up and stops rather - // than retrying. A second interrupt kills the process. - runCtx, stopSignals := signal.NotifyContext(timeoutCtx, os.Interrupt, syscall.SIGTERM) - defer stopSignals() - - runDir, err := os.MkdirTemp("", "gotenberg-integration-") - if err != nil { - fmt.Fprintf(colors.Colored(os.Stdout), "create the run directory: %v\n", err) - os.Exit(1) - } - scenario.RunDir = runDir - - // os.Exit skips the deferred calls: exit cleans up first. - exit := func(code int) { - stopSignals() - err := os.RemoveAll(runDir) - if err != nil { - fmt.Fprintf(colors.Colored(os.Stdout), "warning: remove the run directory: %v\n", err) - } - os.Exit(code) - } - - // Scenarios that failed at least once: reported when they pass on a retry. - var flaky []string - - for attempt := 1; attempt <= maxAttempts; attempt++ { - // Reset the failure collector before each run. - scenario.ResetFailedScenarios() - - // Reclaim subnets leaked by prior runs or failed container starts - // before they exhaust Docker's predefined address pools. - if deleted, err := scenario.PruneOrphanedNetworks(context.Background()); err != nil { - fmt.Fprintf(colors.Colored(os.Stdout), "warning: prune orphaned networks: %v\n", err) - } else if deleted > 0 { - fmt.Fprintf(colors.Colored(os.Stdout), "pruned %d orphaned network(s)\n", deleted) - } - - code := godog.TestSuite{ - Name: "integration", - ScenarioInitializer: scenario.InitializeScenario, - Options: &godog.Options{ - Format: "pretty", - Paths: paths, - Output: colors.Colored(os.Stdout), - Concurrency: concurrency, - Tags: *tags, - DefaultContext: runCtx, - // An undefined or pending step fails the run instead of - // passing it unchecked. - Strict: true, - }, - }.Run() - - // Pooled containers live across scenarios, not across runs: a retry - // starts from fresh ones. - if err := scenario.TerminateDefaultContainers(context.Background()); err != nil { - fmt.Fprintf(colors.Colored(os.Stdout), "warning: %v\n", err) - } - - if runCtx.Err() != nil && timeoutCtx.Err() == nil { - fmt.Fprintf(colors.Colored(os.Stdout), "\n--- interrupted ---\n") - exit(130) - } - - if code == 0 { - if len(flaky) > 0 { - fmt.Fprintf(colors.Colored(os.Stdout), "\n--- %d flaky scenario(s), passed on a retry ---\n%s\n", len(flaky), strings.Join(flaky, "\n")) - } - exit(0) - } - - // A failure the retry cannot target would be dropped from it, and a - // green retry would then hide it. - if unmapped := scenario.UnmappedFailures(); unmapped > 0 { - fmt.Fprintf(colors.Colored(os.Stdout), "\n--- %d failed scenario(s) cannot be retried, failing the run ---\n", unmapped) - exit(code) - } - - failedPaths := scenario.FailedScenarioPaths() - if len(failedPaths) == 0 || attempt == maxAttempts { - exit(code) - } - - for _, path := range failedPaths { - if !slices.Contains(flaky, path) { - flaky = append(flaky, path) - } - } - - fmt.Fprintf(colors.Colored(os.Stdout), - "\n\n--- %d scenario(s) failed, retrying (%d retries left) ---\n\n", - len(failedPaths), maxAttempts-attempt, - ) - - // Next run: only the failed scenarios via file:line paths. - paths = failedPaths - } - - exit(1) +func TestMain(_ *testing.M) { + scenario.RunSuite("integration") } diff --git a/test/integration/scenario/suite.go b/test/integration/scenario/suite.go new file mode 100644 index 00000000..fb69171b --- /dev/null +++ b/test/integration/scenario/suite.go @@ -0,0 +1,165 @@ +package scenario + +import ( + "context" + "fmt" + "os" + "os/signal" + "runtime" + "slices" + "strings" + "syscall" + "time" + + "github.com/cucumber/godog" + "github.com/cucumber/godog/colors" + flag "github.com/spf13/pflag" +) + +// runTimeout bounds a whole run, retries included. It stays below the go test +// timeout of the Makefile. +const runTimeout = 38 * time.Minute + +// RunSuite parses the command line, runs the features under the features/ +// directory of the current directory as the godog suite of the given name, +// retries the failed scenarios, then exits the process with the run's code. +// It never returns. +func RunSuite(name string) { + repository := flag.String("gotenberg-docker-repository", "", "") + version := flag.String("gotenberg-version", "", "") + variant := flag.String("gotenberg-variant", "", "") + platform := flag.String("gotenberg-container-platform", "", "") + concurrencyFlag := flag.Int("concurrency", 0, "") + tags := flag.String("tags", "", "") + keepFailed := flag.String("keep-failed", "", "") + flag.Parse() + + if *platform == "" { + switch runtime.GOARCH { + case "arm64": + *platform = "linux/arm64" + default: + *platform = "linux/amd64" + } + } + + GotenbergDockerRepository = *repository + GotenbergVersion = *version + GotenbergVariant = *variant + GotenbergContainerPlatform = *platform + KeepFailedDir = *keepFailed + + concurrency := *concurrencyFlag + if concurrency <= 0 { + concurrency = runtime.NumCPU() + } + + maxAttempts := 4 // 1 initial run + up to 3 retries + paths := []string{"features"} + + runDir, err := os.MkdirTemp("", "gotenberg-integration-") + if err != nil { + fmt.Fprintf(colors.Colored(os.Stdout), "create the run directory: %v\n", err) + os.Exit(1) + } + RunDir = runDir + + // Steps run on this context: a step that waits on it fails before the go + // test timeout (-timeout 40m in the Makefile) panics, which would skip the + // retries and the report. + timeoutCtx, cancelTimeout := context.WithTimeout(context.Background(), runTimeout) + defer cancelTimeout() + + // An interrupt cancels the steps, then the run cleans up and stops rather + // than retrying. A second interrupt kills the process. + runCtx, stopSignals := signal.NotifyContext(timeoutCtx, os.Interrupt, syscall.SIGTERM) + defer stopSignals() + + // os.Exit skips the deferred calls: exit cleans up first. + exit := func(code int) { + stopSignals() + err := os.RemoveAll(runDir) + if err != nil { + fmt.Fprintf(colors.Colored(os.Stdout), "warning: remove the run directory: %v\n", err) + } + os.Exit(code) + } + + // Scenarios that failed at least once: reported when they pass on a retry. + var flaky []string + + for attempt := 1; attempt <= maxAttempts; attempt++ { + // Reset the failure collector before each run. + ResetFailedScenarios() + + // Reclaim subnets leaked by prior runs or failed container starts + // before they exhaust Docker's predefined address pools. + if deleted, err := PruneOrphanedNetworks(context.Background()); err != nil { + fmt.Fprintf(colors.Colored(os.Stdout), "warning: prune orphaned networks: %v\n", err) + } else if deleted > 0 { + fmt.Fprintf(colors.Colored(os.Stdout), "pruned %d orphaned network(s)\n", deleted) + } + + code := godog.TestSuite{ + Name: name, + ScenarioInitializer: InitializeScenario, + Options: &godog.Options{ + Format: "pretty", + Paths: paths, + Output: colors.Colored(os.Stdout), + Concurrency: concurrency, + Tags: *tags, + DefaultContext: runCtx, + // An undefined or pending step fails the run instead of + // passing it unchecked. + Strict: true, + }, + }.Run() + + // Pooled containers live across scenarios, not across runs: a retry + // starts from fresh ones. + if err := TerminateDefaultContainers(context.Background()); err != nil { + fmt.Fprintf(colors.Colored(os.Stdout), "warning: %v\n", err) + } + + if runCtx.Err() != nil && timeoutCtx.Err() == nil { + fmt.Fprintf(colors.Colored(os.Stdout), "\n--- interrupted ---\n") + exit(130) + } + + if code == 0 { + if len(flaky) > 0 { + fmt.Fprintf(colors.Colored(os.Stdout), "\n--- %d flaky scenario(s), passed on a retry ---\n%s\n", len(flaky), strings.Join(flaky, "\n")) + } + exit(0) + } + + // A failure the retry cannot target would be dropped from it, and a + // green retry would then hide it. + if unmapped := UnmappedFailures(); unmapped > 0 { + fmt.Fprintf(colors.Colored(os.Stdout), "\n--- %d failed scenario(s) cannot be retried, failing the run ---\n", unmapped) + exit(code) + } + + failedPaths := FailedScenarioPaths() + if len(failedPaths) == 0 || attempt == maxAttempts { + exit(code) + } + + for _, path := range failedPaths { + if !slices.Contains(flaky, path) { + flaky = append(flaky, path) + } + } + + fmt.Fprintf(colors.Colored(os.Stdout), + "\n\n--- %d scenario(s) failed, retrying (%d retries left) ---\n\n", + len(failedPaths), maxAttempts-attempt, + ) + + // Next run: only the failed scenarios via file:line paths. + paths = failedPaths + } + + exit(1) +}