mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-12 18:32:14 +01:00
feat: add 7.x source code
This commit is contained in:
45
test/Dockerfile
Normal file
45
test/Dockerfile
Normal file
@@ -0,0 +1,45 @@
|
||||
ARG GOLANG_VERSION
|
||||
ARG DOCKER_REGISTRY
|
||||
ARG GOTENBERG_VERSION
|
||||
ARG GOLANGCI_LINT_VERSION
|
||||
|
||||
FROM golang:$GOLANG_VERSION-stretch as golang
|
||||
|
||||
# We're extending the Gotenberg's Docker image because our code relies on external
|
||||
# dependencies like Google Chrome, LibreOffice, etc.
|
||||
FROM $DOCKER_REGISTRY/gotenberg:$GOTENBERG_VERSION
|
||||
|
||||
USER root
|
||||
|
||||
COPY --from=golang /usr/local/go /usr/local/go
|
||||
COPY ./test/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
|
||||
COPY ./test/golint.sh /usr/bin/golint
|
||||
COPY ./test/gotest.sh /usr/bin/gotest
|
||||
COPY ./test/gotodos.sh /usr/bin/gotodos
|
||||
|
||||
ENV GOPATH /go
|
||||
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
|
||||
ENV CGO_ENABLED 1
|
||||
|
||||
RUN apt-get update -qq &&\
|
||||
apt-get install -y -qq --no-install-recommends \
|
||||
sudo \
|
||||
# gcc for cgo.
|
||||
g++ \
|
||||
gcc \
|
||||
libc6-dev \
|
||||
make \
|
||||
pkg-config &&\
|
||||
rm -rf /var/lib/apt/lists/* &&\
|
||||
mkdir -p "$GOPATH/src" "$GOPATH/bin" &&\
|
||||
chmod -R 777 "$GOPATH" &&\
|
||||
adduser gotenberg sudo &&\
|
||||
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers &&\
|
||||
# We cannot use $PATH in the next command (print $PATH instead of the environment variable value).
|
||||
sed -i 's#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/go/bin:/usr/local/go/bin#g' /etc/sudoers &&\
|
||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin $GOLANGCI_LINT_VERSION
|
||||
|
||||
# Pristine working directory.
|
||||
WORKDIR /tests
|
||||
|
||||
ENTRYPOINT [ "docker-entrypoint.sh" ]
|
||||
59
test/docker-entrypoint.sh
Executable file
59
test/docker-entrypoint.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This entrypoint allows us to set the UID and GID of the host user so that
|
||||
# our testing environment does not override files permissions from the host.
|
||||
# Credits: https://github.com/thecodingmachine/docker-images-php.
|
||||
|
||||
set +e
|
||||
mkdir testing_file_system_rights.foo
|
||||
chmod 700 testing_file_system_rights.foo
|
||||
su gotenberg -c "touch testing_file_system_rights.foo/foo > /dev/null 2>&1"
|
||||
HAS_CONSISTENT_RIGHTS=$?
|
||||
|
||||
if [[ "$HAS_CONSISTENT_RIGHTS" != "0" ]]; then
|
||||
# If not specified, the DOCKER_USER is the owner of the current working directory (heuristic!).
|
||||
DOCKER_USER=`ls -dl $(pwd) | cut -d " " -f 3`
|
||||
else
|
||||
# macOs or Windows.
|
||||
# Note: in most cases, we don't care about the rights (they are not respected).
|
||||
FILE_OWNER=`ls -dl testing_file_system_rights.foo/foo | cut -d " " -f 3`
|
||||
if [[ "$FILE_OWNER" == "root" ]]; then
|
||||
# If root, we are likely on a Windows host.
|
||||
# All files will belong to root, but it does not matter as everybody can write/delete
|
||||
# those (0777 access rights).
|
||||
DOCKER_USER=gotenberg
|
||||
else
|
||||
# In case of a NFS mount (common on macOS), the created files will belong to the NFS user.
|
||||
DOCKER_USER=$FILE_OWNER
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -rf testing_file_system_rights.foo
|
||||
set -e
|
||||
unset HAS_CONSISTENT_RIGHTS
|
||||
|
||||
# Note: DOCKER_USER is either a username (if the user exists in the container),
|
||||
# otherwise a user ID (a user from the host).
|
||||
|
||||
# DOCKER_USER is an ID.
|
||||
if [[ "$DOCKER_USER" =~ ^[0-9]+$ ]] ; then
|
||||
# Let's change the gotenberg user's ID in order to match this free ID.
|
||||
usermod -u $DOCKER_USER -G sudo gotenberg
|
||||
DOCKER_USER=gotenberg
|
||||
fi
|
||||
|
||||
DOCKER_USER_ID=`id -ur $DOCKER_USER`
|
||||
|
||||
# Fix access rights to stdout and stderr.
|
||||
set +e
|
||||
chown $DOCKER_USER /proc/self/fd/{1,2}
|
||||
set -e
|
||||
|
||||
# Install modules.
|
||||
set -x
|
||||
go mod download
|
||||
go mod tidy
|
||||
set +x
|
||||
|
||||
# Run the command with the correct user.
|
||||
exec "sudo" "-E" "-H" "-u" "#$DOCKER_USER_ID" "$@"
|
||||
5
test/golint.sh
Executable file
5
test/golint.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
golangci-lint run
|
||||
6
test/gotest.sh
Executable file
6
test/gotest.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
go test -race -covermode=atomic -coverprofile=/tests/coverage.txt ./...
|
||||
go tool cover -html=coverage.txt -o /tests/coverage.html
|
||||
8
test/gotodos.sh
Executable file
8
test/gotodos.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
golangci-lint run \
|
||||
--no-config \
|
||||
--disable-all \
|
||||
--enable godox
|
||||
1
test/testdata/api/sample1.txt
vendored
Normal file
1
test/testdata/api/sample1.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
BIN
test/testdata/api/sample2.pdf
vendored
Normal file
BIN
test/testdata/api/sample2.pdf
vendored
Normal file
Binary file not shown.
BIN
test/testdata/chromium/html/sample1/font.woff
vendored
Normal file
BIN
test/testdata/chromium/html/sample1/font.woff
vendored
Normal file
Binary file not shown.
15
test/testdata/chromium/html/sample1/footer.html
vendored
Normal file
15
test/testdata/chromium/html/sample1/footer.html
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-size: 30rem;
|
||||
margin: 4rem auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<span class="pageNumber"></span> of <span class="totalPages"></span>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
13
test/testdata/chromium/html/sample1/header.html
vendored
Normal file
13
test/testdata/chromium/html/sample1/header.html
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-size: 8rem;
|
||||
margin: 4rem auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<span class="title"></span>
|
||||
</body>
|
||||
</html>
|
||||
BIN
test/testdata/chromium/html/sample1/img.gif
vendored
Normal file
BIN
test/testdata/chromium/html/sample1/img.gif
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
38
test/testdata/chromium/html/sample1/index.html
vendored
Normal file
38
test/testdata/chromium/html/sample1/index.html
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
|
||||
<title>Gutenberg</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page-break-after">
|
||||
<div class="center">
|
||||
<h1>Gutenberg</h1>
|
||||
<img src="img.gif">
|
||||
</div>
|
||||
|
||||
<blockquote cite="https://sites.google.com/site/johanngutenbergper5/q">
|
||||
<p>It is a press, certainly, but a press from which shall flow in inexhaustible streams...Through it, God will spread His Word. A spring of truth shall flow from it: like a new star it shall scatter the darkness of ignorance, and cause a light heretofore unknown to shine amongst men.</p>
|
||||
<footer>— <a href="https://sites.google.com/site/johanngutenbergper5/q">Johannes Gutenberg</a></cite></footer>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<div class="page-break-after">
|
||||
<h2>This paragraph use the default font</h2>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
||||
|
||||
<h2>This paragraph use a Google font</h2>
|
||||
<p class="google-font">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
||||
|
||||
<h2>This paragraph use a local font</h2>
|
||||
<p class="local-font">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
||||
</div>
|
||||
|
||||
<div class="center">
|
||||
<h1>This image is loaded from a URL</h1>
|
||||
<img src="https://gutendev.com/wp-content/uploads/2018/10/01_03-1.jpg">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
28
test/testdata/chromium/html/sample1/style.css
vendored
Normal file
28
test/testdata/chromium/html/sample1/style.css
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
.center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.google-font {
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Local';
|
||||
src: url('font.woff') format('woff');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.local-font {
|
||||
font-family: 'Local'
|
||||
}
|
||||
|
||||
@media print {
|
||||
.page-break-after {
|
||||
page-break-after: always;
|
||||
}
|
||||
}
|
||||
28
test/testdata/chromium/html/sample2/index.html
vendored
Normal file
28
test/testdata/chromium/html/sample2/index.html
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Gutenberg</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p id="status">
|
||||
No window.status
|
||||
</p>
|
||||
|
||||
<script type="application/javascript">
|
||||
const delay = ms => new Promise(res => setTimeout(res, ms))
|
||||
|
||||
const changeStatus = async (status) => {
|
||||
await delay(2000)
|
||||
console.log('waited 2s')
|
||||
|
||||
document.getElementById('status').innerText = 'window.status === ' + status
|
||||
|
||||
window.status = status
|
||||
};
|
||||
|
||||
changeStatus('ready')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
BIN
test/testdata/chromium/markdown/sample1/font.woff
vendored
Normal file
BIN
test/testdata/chromium/markdown/sample1/font.woff
vendored
Normal file
Binary file not shown.
15
test/testdata/chromium/markdown/sample1/footer.html
vendored
Normal file
15
test/testdata/chromium/markdown/sample1/footer.html
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-size: 8rem;
|
||||
margin: 4rem auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<span class="pageNumber"></span> of <span class="totalPages"></span>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
13
test/testdata/chromium/markdown/sample1/header.html
vendored
Normal file
13
test/testdata/chromium/markdown/sample1/header.html
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-size: 8rem;
|
||||
margin: 4rem auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<span class="title"></span>
|
||||
</body>
|
||||
</html>
|
||||
BIN
test/testdata/chromium/markdown/sample1/img.gif
vendored
Normal file
BIN
test/testdata/chromium/markdown/sample1/img.gif
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
34
test/testdata/chromium/markdown/sample1/index.html
vendored
Normal file
34
test/testdata/chromium/markdown/sample1/index.html
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
|
||||
<title>Gutenberg</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page-break-after">
|
||||
<div class="center">
|
||||
<h1>Gutenberg</h1>
|
||||
<img src="img.gif">
|
||||
</div>
|
||||
|
||||
<blockquote cite="https://sites.google.com/site/johanngutenbergper5/q">
|
||||
<p>It is a press, certainly, but a press from which shall flow in inexhaustible streams...Through it, God will spread His Word. A spring of truth shall flow from it: like a new star it shall scatter the darkness of ignorance, and cause a light heretofore unknown to shine amongst men.</p>
|
||||
<footer>— <a href="https://sites.google.com/site/johanngutenbergper5/q">Johannes Gutenberg</a></cite></footer>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<div class="page-break-after">
|
||||
{{ toHTML "markdown1.md" }}
|
||||
|
||||
<div class="google-font">
|
||||
{{ toHTML "markdown2.md" }}
|
||||
</div>
|
||||
|
||||
<div class="local-font">
|
||||
{{ toHTML "markdown3.md" }}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
3
test/testdata/chromium/markdown/sample1/markdown1.md
vendored
Normal file
3
test/testdata/chromium/markdown/sample1/markdown1.md
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
## This paragraph uses the default font and has been generated from a markdown file
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
3
test/testdata/chromium/markdown/sample1/markdown2.md
vendored
Normal file
3
test/testdata/chromium/markdown/sample1/markdown2.md
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
## This paragraph uses a Google font and has been generated from a markdown file
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
3
test/testdata/chromium/markdown/sample1/markdown3.md
vendored
Normal file
3
test/testdata/chromium/markdown/sample1/markdown3.md
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
## This paragraph uses a local font and has been generated from a markdown file
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
28
test/testdata/chromium/markdown/sample1/style.css
vendored
Normal file
28
test/testdata/chromium/markdown/sample1/style.css
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
.center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.google-font {
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Local';
|
||||
src: url('font.woff') format('woff');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.local-font {
|
||||
font-family: 'Local'
|
||||
}
|
||||
|
||||
@media print {
|
||||
.page-break-after {
|
||||
page-break-after: always;
|
||||
}
|
||||
}
|
||||
23
test/testdata/chromium/markdown/sample2/index.html
vendored
Normal file
23
test/testdata/chromium/markdown/sample2/index.html
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Gutenberg</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page-break-after">
|
||||
<div class="center">
|
||||
<h1>Gutenberg</h1>
|
||||
</div>
|
||||
|
||||
<blockquote cite="https://sites.google.com/site/johanngutenbergper5/q">
|
||||
<p>It is a press, certainly, but a press from which shall flow in inexhaustible streams...Through it, God will spread His Word. A spring of truth shall flow from it: like a new star it shall scatter the darkness of ignorance, and cause a light heretofore unknown to shine amongst men.</p>
|
||||
<footer>— <a href="https://sites.google.com/site/johanngutenbergper5/q">Johannes Gutenberg</a></cite></footer>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<div class="page-break-after">
|
||||
{{ toHTML "markdown.md" }}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
15
test/testdata/chromium/url/sample1/footer.html
vendored
Normal file
15
test/testdata/chromium/url/sample1/footer.html
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-size: 8rem;
|
||||
margin: 4rem auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<span class="pageNumber"></span> of <span class="totalPages"></span>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
13
test/testdata/chromium/url/sample1/header.html
vendored
Normal file
13
test/testdata/chromium/url/sample1/header.html
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-size: 8rem;
|
||||
margin: 4rem auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<span class="title"></span>
|
||||
</body>
|
||||
</html>
|
||||
8206
test/testdata/chromium/url/sample2/footer.html
vendored
Normal file
8206
test/testdata/chromium/url/sample2/footer.html
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8206
test/testdata/chromium/url/sample2/header.html
vendored
Normal file
8206
test/testdata/chromium/url/sample2/header.html
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
test/testdata/libreoffice/sample1.docx
vendored
Normal file
BIN
test/testdata/libreoffice/sample1.docx
vendored
Normal file
Binary file not shown.
BIN
test/testdata/pdfengines/sample1.pdf
vendored
Normal file
BIN
test/testdata/pdfengines/sample1.pdf
vendored
Normal file
Binary file not shown.
BIN
test/testdata/pdfengines/sample2.pdf
vendored
Normal file
BIN
test/testdata/pdfengines/sample2.pdf
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user