forked from thecodingmachine/gotenberg-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffice_test.go
53 lines (48 loc) · 1.46 KB
/
office_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
46
47
48
49
50
51
52
53
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 TestOffice(t *testing.T) {
c := &Client{Hostname: "http://localhost:3000"}
doc, err := NewDocumentFromPath("document.docx", test.OfficeTestFilePath(t, "document.docx"))
require.Nil(t, err)
req := NewOfficeRequest(doc)
req.ResultFilename("foo.pdf")
req.WaitTimeout(5)
req.Landscape(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 TestOfficePageRanges(t *testing.T) {
c := &Client{Hostname: "http://localhost:3000"}
doc, err := NewDocumentFromPath("document.docx", test.OfficeTestFilePath(t, "document.docx"))
require.Nil(t, err)
req := NewOfficeRequest(doc)
req.PageRanges("1-1")
resp, err := c.Post(req)
assert.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
}
func TestOfficeWebhook(t *testing.T) {
c := &Client{Hostname: "http://localhost:3000"}
doc, err := NewDocumentFromPath("document.docx", test.OfficeTestFilePath(t, "document.docx"))
require.Nil(t, err)
req := NewOfficeRequest(doc)
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)
}