Repository navigation
Expand file tree
/
Copy pathconvert_test.go
More file actions
74 lines (61 loc) · 1.79 KB
/
Copy pathconvert_test.go
File metadata and controls
74 lines (61 loc) · 1.79 KB
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
package convertapi
import (
"net/url"
"os"
"path"
"testing"
"github.com/ConvertAPI/convertapi-go/pkg"
"github.com/ConvertAPI/convertapi-go/pkg/config"
"github.com/ConvertAPI/convertapi-go/pkg/param"
"github.com/stretchr/testify/assert"
)
// The tests in this file call the ConvertAPI API. They run only when CONVERTAPI_TOKEN is set, against
// CONVERTAPI_BASE_URL when it is set (CI uses the staging API) and the production API otherwise.
func liveConfig(t *testing.T) *config.Config {
t.Helper()
token := os.Getenv("CONVERTAPI_TOKEN")
if token == "" {
t.Skip("CONVERTAPI_TOKEN is not set, so the API tests are skipped")
}
conf := config.NewDefault(token)
if base := os.Getenv("CONVERTAPI_BASE_URL"); base != "" {
baseURL, err := url.ParseRequestURI(base)
if err != nil {
t.Fatalf("CONVERTAPI_BASE_URL %q: %v", base, err)
}
conf.BaseURL = baseURL
}
config.Default = conf
return conf
}
func TestConvertPath(t *testing.T) {
liveConfig(t)
file, errs := convertapi.ConvertPath("assets/test.docx", path.Join(t.TempDir(), "convertapi-test.pdf"))
assert.Nil(t, errs)
assert.NotEmpty(t, file.Name())
}
func TestChained(t *testing.T) {
liveConfig(t)
jpgRes := convertapi.Convert("docx", "jpg", []param.IParam{
param.NewPath("file", "assets/test.docx", nil),
}, nil)
zipRes := convertapi.Convert("any", "zip", []param.IParam{
param.NewResult("files", jpgRes, nil),
}, nil)
zipCost, err := zipRes.Cost()
assert.Nil(t, err)
assert.NotEmpty(t, zipCost)
files, err := zipRes.Files()
assert.Nil(t, err)
if assert.NotEmpty(t, files) {
assert.Equal(t, "test.zip", files[0].FileName)
}
}
func TestUserInfo(t *testing.T) {
conf := liveConfig(t)
user, err := convertapi.UserInfo(conf)
assert.Nil(t, err)
if assert.NotNil(t, user) {
assert.NotEmpty(t, user.ConversionsTotal)
}
}