forked from cloudinary/cloudinary-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudinary_test.go
107 lines (83 loc) · 2.27 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
package cloudinary
import (
"context"
"github.com/cloudinary/cloudinary-go/internal/cldtest"
"log"
"testing"
"github.com/cloudinary/cloudinary-go/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("cloudinary://key:secret@test123")
if c.Config.Cloud.CloudName != "test123" {
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("test123", "key", "secret")
if c.Config.Cloud.CloudName != "test123" {
t.Error("Failed creating Cloudinary instance from parameters.")
}
c, _ = NewFromOAuthToken("test123", "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI4")
if c.Config.Cloud.CloudName != "test123" {
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: false,
UseFilename: true,
Overwrite: true,
}
resp, err := c.Upload.Upload(ctx, "https://cloudinary-res.cloudinary.com/image/upload/cloudinary_logo.png", 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())
}