-
Notifications
You must be signed in to change notification settings - Fork 4
/
doctron_test.go
119 lines (111 loc) · 3.59 KB
/
doctron_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package doctron
import (
"context"
"io/ioutil"
"os"
"testing"
"time"
)
const domain = "http://47.52.25.206:8080"
const defaultUsername = "doctron"
const defaultPassword = "lampnick"
func TestHTML2Pdf(t *testing.T) {
start := time.Now()
defer func() {
t.Logf("elapsed: %v", time.Since(start))
}()
client := NewClient(context.Background(), domain, defaultUsername, defaultPassword)
req := NewDefaultHTML2PdfRequestDTO()
req.ConvertURL = "http://doctron.lampnick.com/doctron.html"
req.WaitingTime = 1000
response, err := client.HTML2Pdf(req)
if err != nil {
t.Fatalf("HTML2Pdf err: %s", err.Error())
}
t.Logf("%d", len(response.Data))
fn := "./test/HTML2Pdf.pdf"
os.Remove(fn)
ioutil.WriteFile(fn, response.Data, os.ModePerm)
}
func TestHTML2PdfAndUpload(t *testing.T) {
start := time.Now()
defer func() {
t.Logf("elapsed: %v", time.Since(start))
}()
client := NewClient(context.Background(), domain, defaultUsername, defaultPassword)
req := NewDefaultHTML2PdfRequestDTO()
req.ConvertURL = "http://doctron.lampnick.com/doctron.html"
req.UploadKey = "test.pdf"
response, err := client.HTML2PdfAndUpload(req)
if err != nil {
t.Fatalf("HTML2PdfAndUpload err: %s", err.Error())
}
t.Logf("UploadedURL: %s", response.UploadedURL)
}
func TestHTML2Image(t *testing.T) {
start := time.Now()
defer func() {
t.Logf("elapsed: %v", time.Since(start))
}()
client := NewClient(context.Background(), domain, defaultUsername, defaultPassword)
req := NewDefaultHTML2ImageRequestDTO()
req.WaitingTime = 1000
req.ConvertURL = "http://doctron.lampnick.com/doctron.html"
response, err := client.HTML2Image(req)
if err != nil {
t.Fatalf("HTML2Image err: %s", err.Error())
}
t.Logf("%d", len(response.Data))
fn := "./test/HTML2Image.png"
os.Remove(fn)
ioutil.WriteFile(fn, response.Data, os.ModePerm)
}
func TestHTML2ImageAndUpload(t *testing.T) {
start := time.Now()
defer func() {
t.Logf("elapsed: %v", time.Since(start))
}()
client := NewClient(context.Background(), domain, defaultUsername, defaultPassword)
req := NewDefaultHTML2ImageRequestDTO()
req.ConvertURL = "http://doctron.lampnick.com/doctron.html"
req.UploadKey = "test.png"
response, err := client.HTML2ImageAndUpload(req)
if err != nil {
t.Fatalf("HTML2ImageAndUpload err: %s", err.Error())
}
t.Logf("UploadedURL: %s", response.UploadedURL)
}
func TestPdfAddWatermark(t *testing.T) {
start := time.Now()
defer func() {
t.Logf("elapsed: %v", time.Since(start))
}()
client := NewClient(context.Background(), domain, defaultUsername, defaultPassword)
req := NewDefaultPdfWatermarkRequestDTO()
req.ConvertURL = "https://qjhdqx-prod.oss-cn-zhangjiakou.aliyuncs.com/test.pdf"
req.ImageURL = "https://www.baidu.com/img/flexible/logo/pc/result.png"
response, err := client.PdfAddWatermark(req)
if err != nil {
t.Fatalf("PdfAddWatermark err: %s", err.Error())
}
t.Logf("%d", len(response.Data))
fn := "./test/PdfAddWatermark.pdf"
os.Remove(fn)
ioutil.WriteFile(fn, response.Data, os.ModePerm)
}
func TestPdfAddWatermarkAndUpload(t *testing.T) {
start := time.Now()
defer func() {
t.Logf("elapsed: %v", time.Since(start))
}()
client := NewClient(context.Background(), domain, defaultUsername, defaultPassword)
req := NewDefaultPdfWatermarkRequestDTO()
req.ConvertURL = "https://qjhdqx-prod.oss-cn-zhangjiakou.aliyuncs.com/test.pdf"
req.ImageURL = "https://www.baidu.com/img/flexible/logo/pc/result.png"
req.UploadKey = "PdfAddWatermarkAndUpload.pdf"
response, err := client.PdfAddWatermarkAndUpload(req)
if err != nil {
t.Fatalf("PdfAddWatermarkAndUpload err: %s", err.Error())
}
t.Logf("UploadedURL: %s", response.UploadedURL)
}