-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconvert_test.go
More file actions
56 lines (43 loc) · 1.37 KB
/
convert_test.go
File metadata and controls
56 lines (43 loc) · 1.37 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
package convertapi
import (
"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"
"os"
"path"
"testing"
)
var authCred = os.Getenv("CONVERTAPI_SECRET")
func TestSetup(t *testing.T) {
config.Default = config.NewDefault(authCred)
assert.Equal(t, config.Default.CaTransport.AuthCred, authCred)
}
func TestConvertPath(t *testing.T) {
config.Default = config.NewDefault(authCred)
file, errs := convertapi.ConvertPath("assets/test.docx", path.Join(os.TempDir(), "convertapi-test.pdf"))
assert.Nil(t, errs)
assert.NotEmpty(t, file.Name())
}
func TestChained(t *testing.T) {
config.Default = config.NewDefault(authCred)
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)
assert.Equal(t, "test.zip", files[0].FileName)
}
func TestUserInfo(t *testing.T) {
config.Default = config.NewDefault(authCred)
user, err := convertapi.UserInfo(nil)
assert.Nil(t, err)
assert.NotEmpty(t, user.ConversionsTotal)
assert.NotEmpty(t, user.ConversionsConsumed)
}