-
Notifications
You must be signed in to change notification settings - Fork 21
/
cloudinary_test.go
108 lines (84 loc) · 2.33 KB
/
cloudinary_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
package cloudinary
import (
"context"
"github.com/cloudinary/cloudinary-go/v2/api"
"github.com/cloudinary/cloudinary-go/v2/internal/cldtest"
"log"
"testing"
"github.com/cloudinary/cloudinary-go/v2/api/uploader"
)
var c, _ = New()
var ctx = context.Background()
func TestCloudinary_CreateInstance(t *testing.T) {
c, _ := New()
if c.Config.Cloud.CloudName == "" {
t.Error("Please set up CLOUDINARY_URL environment variable to run the test.")
}
c, _ = NewFromURL(cldtest.CldURL)
if c.Config.Cloud.CloudName != cldtest.CloudName {
t.Error("Failed creating Cloudinary instance from Cloudinary URL.")
}
c, err := NewFromURL("")
if err == nil || err.Error() != "must provide CLOUDINARY_URL" {
t.Error("Error expected, got: ", err)
}
c, _ = NewFromParams(cldtest.CloudName, cldtest.APIKey, cldtest.APISecret)
if c.Config.Cloud.CloudName != cldtest.CloudName {
t.Error("Failed creating Cloudinary instance from parameters.")
}
c, _ = NewFromOAuthToken(cldtest.CloudName, "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI4")
if c.Config.Cloud.CloudName != cldtest.CloudName {
t.Error("Failed creating Cloudinary instance from OAuth token.")
}
}
func TestCloudinary_Upload(t *testing.T) {
params := uploader.UploadParams{
PublicID: "test_image",
Eager: "w_500,h_500",
UniqueFilename: api.Bool(false),
UseFilename: api.Bool(true),
Overwrite: api.Bool(true),
}
resp, err := c.Upload.Upload(ctx, cldtest.LogoURL, params)
if err != nil {
t.Error("Uploader failed: ", err)
}
if resp == nil || resp.PublicID != "test_image" {
t.Error("Uploader failed: ", resp)
}
}
func TestCloudinary_Admin(t *testing.T) {
resp, err := c.Admin.Ping(ctx)
if err != nil {
t.Error("Admin API failed: ", err)
}
if resp == nil || resp.Status != "ok" {
t.Error("Admin API failed: ", resp)
}
}
func TestCloudinary_Asset(t *testing.T) {
c.Config.URL.Secure = true
c.Config.URL.SecureCDNSubDomain = true
i, err := c.Image(cldtest.PublicID)
if err != nil {
t.Fatal(err)
}
i.DeliveryType = "fetch"
i.Version = 123
log.Println(i.String())
v, err := c.Video(cldtest.VideoPublicID)
if err != nil {
t.Fatal(err)
}
log.Println(v.String())
f, err := c.File("sample_file")
if err != nil {
t.Fatal(err)
}
log.Println(f.String())
m, err := c.Media(cldtest.PublicID)
if err != nil {
t.Fatal(err)
}
log.Println(m.String())
}