-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudinary_test.go
45 lines (42 loc) · 1.4 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
package cloudinary
import (
"net/url"
"testing"
)
// func Example() {
// //Dial takes a usual cloudinary auth link and returns *Service and error.
// service, err := initService("cloudinary://api_key:api_secret@cloud_name")
// if err != nil {
// //Do something with error
// }
// //After initialization we receive a service which is ready to use.
// fmt.Println(service)
// }
func TestInitService(t *testing.T) {
t.Run("Sample test case", func(t *testing.T) {
service, err := NewService("cloudinary://api_key:api_secret@cloud_name")
if err != nil {
t.Errorf("Unexpected error %v", err)
}
upURL, err := url.Parse("https://api.cloudinary.com/v1_1/cloud_name/image/upload/")
if err != nil {
t.Errorf("Unexpected error:%v", err)
}
admURL, err := url.Parse("https://api_key:[email protected]/v1_1/cloud_name")
if err != nil {
t.Errorf("Unexpected error:%v", err)
}
testService := &Service{"cloud_name", "api_key", "api_secret", upURL, admURL, false, false, 0}
testAdmLink := testService.adminURL.String()
serviceAdmLink := service.adminURL.String()
if testAdmLink != serviceAdmLink {
t.Errorf("Not equal adminURL %v, %v", testAdmLink, serviceAdmLink)
}
})
t.Run("No host provided", func(t *testing.T) {
_, err := NewService("https://api_key:api_secret@cloud_name")
if err != errNotCloudinary {
t.Errorf("Expected error %v, got %v", errNotCloudinary, err)
}
})
}