forked from gotsunami/go-cloudinary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransformation_test.go
More file actions
52 lines (47 loc) · 1.61 KB
/
transformation_test.go
File metadata and controls
52 lines (47 loc) · 1.61 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
package cloudinary
import (
"fmt"
"testing"
)
func TestTransformImage(t *testing.T) {
srv := Service{cloudName: "demo"}
publicID := "yellow_tulip.jpg"
tt := []struct {
name string
url string
transformations []Transformation
}{
{
name: "No transformations",
url: fmt.Sprintf("%v/%v/image/upload//%v", baseResourceUrl, srv.CloudName(), publicID),
},
{
name: "Height transformation",
transformations: []Transformation{SizeTransformation{Height: 100}},
url: fmt.Sprintf("%v/%v/image/upload/c_fit,h_100/%v", baseResourceUrl, srv.CloudName(), publicID),
},
{
name: "Width transformation",
transformations: []Transformation{SizeTransformation{Width: 100}},
url: fmt.Sprintf("%v/%v/image/upload/c_fit,w_100/%v", baseResourceUrl, srv.CloudName(), publicID),
},
{
name: "Width and height transformations",
transformations: []Transformation{SizeTransformation{Height: 100, Width: 100}},
url: fmt.Sprintf("%v/%v/image/upload/c_fit,w_100,h_100/%v", baseResourceUrl, srv.CloudName(), publicID),
},
{
name: "Width and invalid height transformations",
transformations: []Transformation{SizeTransformation{Height: -100, Width: 100}},
url: fmt.Sprintf("%v/%v/image/upload/c_fit,w_100/%v", baseResourceUrl, srv.CloudName(), publicID),
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
url := srv.TransformedImageURL(publicID, tc.transformations...)
if url != tc.url {
t.Errorf("Expected to get %v but actually got %v", tc.url, url)
}
})
}
}