-
Notifications
You must be signed in to change notification settings - Fork 1
/
office_test.go
55 lines (51 loc) · 1.58 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
54
55
package gotenberg
import (
"context"
"fmt"
"github.com/commitsmart/gotenberg-go-client/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
)
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.PageRanges("1-1")
req.Landscape(true)
dirPath, err := test.Rand()
require.Nil(t, err)
dest := fmt.Sprintf("%s/foo.pdf", dirPath)
err = c.Store(context.Background(), 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(context.Background(), 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.WebhookErrorURL("https://google.com")
req.WaitTimeout(5.0)
req.AddWebhookURLHTTPHeader("A-Header", "Foo")
resp, err := c.Post(context.Background(), req)
assert.Nil(t, err)
assert.Equal(t, 204, resp.StatusCode)
}