Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
fixing #3
Browse files Browse the repository at this point in the history
  • Loading branch information
gulien committed Mar 19, 2019
1 parent a829bcc commit 8fcda3b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func multipartForm(req Request) (*bytes.Buffer, string, error) {
writer := multipart.NewWriter(body)
defer writer.Close()
for filename, fpath := range req.getFormFiles() {
// https://github.com/thecodingmachine/gotenberg-go-client/issues/3
if fpath == "" {
continue
}
in, err := os.Open(fpath)
if err != nil {
return nil, "", fmt.Errorf("%s: opening file: %v", filename, err)
Expand Down
17 changes: 17 additions & 0 deletions html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ func TestHTML(t *testing.T) {
assert.Nil(t, err)
}

func TestHTMLWithoutHeaderFooter(t *testing.T) {
c := &Client{Hostname: "http://localhost:3000"}
req, err := NewHTMLRequest(test.HTMLTestFilePath(t, "index.html"))
require.Nil(t, err)
req.SetPaperSize(A4)
req.SetMargins(NormalMargins)
req.SetLandscape(false)
dirPath, err := test.Rand()
require.Nil(t, err)
dest := fmt.Sprintf("%s/foo.pdf", dirPath)
err = c.Store(req, dest)
assert.Nil(t, err)
assert.FileExists(t, dest)
err = os.RemoveAll(dirPath)
assert.Nil(t, err)
}

func TestConcurrentHTML(t *testing.T) {
for i := 0; i < 10; i++ {
go func() {
Expand Down
22 changes: 22 additions & 0 deletions markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ func TestMarkdown(t *testing.T) {
assert.Nil(t, err)
}

func TestMarkdownWithoutHeaderFooter(t *testing.T) {
c := &Client{Hostname: "http://localhost:3000"}
req, err := NewMarkdownRequest(
test.MarkdownTestFilePath(t, "index.html"),
test.MarkdownTestFilePath(t, "paragraph1.md"),
test.MarkdownTestFilePath(t, "paragraph2.md"),
test.MarkdownTestFilePath(t, "paragraph3.md"),
)
require.Nil(t, err)
req.SetPaperSize(A4)
req.SetMargins(NormalMargins)
req.SetLandscape(false)
dirPath, err := test.Rand()
require.Nil(t, err)
dest := fmt.Sprintf("%s/foo.pdf", dirPath)
err = c.Store(req, dest)
assert.Nil(t, err)
assert.FileExists(t, dest)
err = os.RemoveAll(dirPath)
assert.Nil(t, err)
}

func TestConcurrentMarkdown(t *testing.T) {
for i := 0; i < 10; i++ {
go func() {
Expand Down
15 changes: 15 additions & 0 deletions url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ func TestURL(t *testing.T) {
require.Nil(t, err)
err = req.SetFooter(test.URLTestFilePath(t, "footer.html"))
require.Nil(t, err)
req.SetPaperSize(A4)
req.SetMargins(NormalMargins)
req.SetLandscape(false)
dirPath, err := test.Rand()
require.Nil(t, err)
dest := fmt.Sprintf("%s/foo.pdf", dirPath)
err = c.Store(req, dest)
assert.Nil(t, err)
assert.FileExists(t, dest)
err = os.RemoveAll(dirPath)
assert.Nil(t, err)
}

func TestURLWithoutHeaderFooter(t *testing.T) {
c := &Client{Hostname: "http://localhost:3000"}
req := NewURLRequest("http://google.com")
req.SetPaperSize(A4)
req.SetMargins(NormalMargins)
req.SetLandscape(false)
Expand Down

0 comments on commit 8fcda3b

Please sign in to comment.