forked from thecodingmachine/gotenberg-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_test.go
45 lines (41 loc) · 1.33 KB
/
merge_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gotenberg
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thecodingmachine/gotenberg-go-client/v7/test"
)
func TestMerge(t *testing.T) {
c := &Client{Hostname: "http://localhost:3000"}
pdf1, err := NewDocumentFromPath("gotenberg1.pdf", test.PDFTestFilePath(t, "gotenberg.pdf"))
require.Nil(t, err)
pdf2, err := NewDocumentFromPath("gotenberg2.pdf", test.PDFTestFilePath(t, "gotenberg.pdf"))
require.Nil(t, err)
req := NewMergeRequest(pdf1, pdf2)
req.ResultFilename("foo.pdf")
req.WaitTimeout(5)
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 TestMergeWebhook(t *testing.T) {
c := &Client{Hostname: "http://localhost:3000"}
pdf1, err := NewDocumentFromPath("gotenberg1.pdf", test.PDFTestFilePath(t, "gotenberg.pdf"))
require.Nil(t, err)
pdf2, err := NewDocumentFromPath("gotenberg2.pdf", test.PDFTestFilePath(t, "gotenberg.pdf"))
require.Nil(t, err)
req := NewMergeRequest(pdf1, pdf2)
req.WebhookURL("https://google.com")
req.WebhookURLTimeout(5.0)
req.AddWebhookURLHTTPHeader("A-Header", "Foo")
resp, err := c.Post(req)
assert.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
}