adding test for printer package

This commit is contained in:
Julien Neuhart
2019-08-18 17:31:07 +02:00
parent 6964124c1b
commit 2fee966fc8
11 changed files with 346 additions and 79 deletions

View File

@@ -11,41 +11,51 @@ import (
"github.com/stretchr/testify/require"
)
// MergeMultipartForm returns the body
// for a multipart/form-data request with all
// files under "pdf" folder.
/*
MergeMultipartForm returns the body
for a multipart/form-data request with all
files under "testdata/pdf" folder.
*/
func MergeMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
fpaths := MergeFpaths(t)
return multipartForm(t, "pdf", formValues, fpaths)
}
// HTMLMultipartForm returns the body
// for a multipart/form-data request with all
// files under "html" folder.
/*
HTMLMultipartForm returns the body
for a multipart/form-data request with all
files under "testdata/html" folder.
*/
func HTMLMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
// TODO
return multipartForm(t, "html", formValues, []string{})
fpaths := HTMLFpaths(t)
return multipartForm(t, "html", formValues, fpaths)
}
// URLMultipartForm returns the body
// for a multipart/form-data request with all
// files under "url" folder.
/*
URLMultipartForm returns the body
for a multipart/form-data request with all
files under "testdata/url" folder.
*/
func URLMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
// TODO
return multipartForm(t, "url", formValues, []string{})
fpaths := URLFpaths(t)
return multipartForm(t, "url", formValues, fpaths)
}
// MarkdownMultipartForm returns the body
// for a multipart/form-data request with all
// files under "markdown" folder.
/*
MarkdownMultipartForm returns the body
for a multipart/form-data request with all
files under "testdata/markdown" folder.
*/
func MarkdownMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
// TODO
return multipartForm(t, "markdown", formValues, []string{})
fpaths := MarkdownFpaths(t)
return multipartForm(t, "markdown", formValues, fpaths)
}
// OfficeMultipartForm returns the body
// for a multipart/form-data request with all
// files under "office" folder.
/*
OfficeMultipartForm returns the body
for a multipart/form-data request with all
files under "testdata/office" folder.
*/
func OfficeMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
fpaths := OfficeFpaths(t)
return multipartForm(t, "office", formValues, fpaths)

View File

@@ -21,8 +21,8 @@ func GenerateDestination() string {
return fmt.Sprintf("/tmp/%s.pdf", xrand.Get())
}
// MergeFpaths return the paths
// of the PDF files used in tests.
// MergeFpaths return the paths of all
// files under "testdata/pdf" folder.
func MergeFpaths(t *testing.T) []string {
return []string{
fpath(t, "pdf", "gotenberg.pdf"),
@@ -30,8 +30,46 @@ func MergeFpaths(t *testing.T) []string {
}
}
// OfficeFpaths return the paths
// of the Office documents used in tests.
// HTMLFpaths return the paths of all
// files under "testdata/html" folder.
func HTMLFpaths(t *testing.T) []string {
return []string{
fpath(t, "html", "index.html"),
fpath(t, "html", "header.html"),
fpath(t, "html", "footer.html"),
fpath(t, "html", "style.css"),
fpath(t, "html", "img.gif"),
fpath(t, "html", "font.woff"),
}
}
// URLFpaths return the paths of all
// files under "testdata/url" folder.
func URLFpaths(t *testing.T) []string {
return []string{
fpath(t, "url", "header.html"),
fpath(t, "url", "footer.html"),
}
}
// MarkdownFpaths return the paths of all
// files under "testdata/markdown" folder.
func MarkdownFpaths(t *testing.T) []string {
return []string{
fpath(t, "markdown", "index.html"),
fpath(t, "markdown", "header.html"),
fpath(t, "markdown", "footer.html"),
fpath(t, "markdown", "style.css"),
fpath(t, "markdown", "img.gif"),
fpath(t, "markdown", "font.woff"),
fpath(t, "markdown", "paragraph1.md"),
fpath(t, "markdown", "paragraph2.md"),
fpath(t, "markdown", "paragraph3.md"),
}
}
// OfficeFpaths return the paths of all
// files under "testdata/office" folder.
func OfficeFpaths(t *testing.T) []string {
return []string{
fpath(t, "office", "document.docx"),