@@ -21,64 +21,6 @@ import (
2121 "github.com/stretchr/testify/require"
2222)
2323
24- func TestAliOSSLocation (t * testing.T ) {
25- cases := []struct {
26- name string
27- conf AliOSSConfig
28- storagePath string
29- want string
30- }{
31- {
32- name : "normal" ,
33- conf : AliOSSConfig {Bucket : "mybucket" , Endpoint : "oss-region.aliyuncs.com" },
34- storagePath : "foo.mp4" ,
35- want : "https://mybucket.oss-region.aliyuncs.com/foo.mp4" ,
36- },
37- {
38- name : "endpoint with https:// prefix" ,
39- conf : AliOSSConfig {Bucket : "mybucket" , Endpoint : "https://oss-region.aliyuncs.com" },
40- storagePath : "foo.mp4" ,
41- want : "https://mybucket.oss-region.aliyuncs.com/foo.mp4" ,
42- },
43- {
44- name : "endpoint with http:// prefix" ,
45- conf : AliOSSConfig {Bucket : "mybucket" , Endpoint : "http://oss-region.aliyuncs.com" },
46- storagePath : "foo.mp4" ,
47- want : "https://mybucket.oss-region.aliyuncs.com/foo.mp4" ,
48- },
49- {
50- name : "nested path" ,
51- conf : AliOSSConfig {Bucket : "mybucket" , Endpoint : "oss-region.aliyuncs.com" },
52- storagePath : "folder/sub/foo.mp4" ,
53- want : "https://mybucket.oss-region.aliyuncs.com/folder/sub/foo.mp4" ,
54- },
55- {
56- name : "storagePath with leading slash" ,
57- conf : AliOSSConfig {Bucket : "mybucket" , Endpoint : "oss-region.aliyuncs.com" },
58- storagePath : "/foo.mp4" ,
59- want : "https://mybucket.oss-region.aliyuncs.com/foo.mp4" ,
60- },
61- {
62- name : "space in key" ,
63- conf : AliOSSConfig {Bucket : "mybucket" , Endpoint : "oss-region.aliyuncs.com" },
64- storagePath : "folder/my file.mp4" ,
65- want : "https://mybucket.oss-region.aliyuncs.com/folder/my%20file.mp4" ,
66- },
67- {
68- name : "unicode in key" ,
69- conf : AliOSSConfig {Bucket : "mybucket" , Endpoint : "oss-region.aliyuncs.com" },
70- storagePath : "café/résumé.mp4" ,
71- want : "https://mybucket.oss-region.aliyuncs.com/caf%C3%A9/r%C3%A9sum%C3%A9.mp4" ,
72- },
73- }
74- for _ , tc := range cases {
75- s := & aliOSSStorage {conf : & tc .conf }
76- got := s .location (tc .storagePath )
77- require .Equal (t , tc .want , got , tc .name )
78- requireWellFormedHTTPLocation (t , got , tc .name )
79- }
80- }
81-
8224func TestAzureLocation (t * testing.T ) {
8325 cases := []struct {
8426 name string
@@ -143,178 +85,6 @@ func TestAzureLocation(t *testing.T) {
14385 }
14486}
14587
146- func TestGCPLocation (t * testing.T ) {
147- cases := []struct {
148- name string
149- conf GCPConfig
150- storagePath string
151- want string
152- }{
153- {
154- name : "normal" ,
155- conf : GCPConfig {Bucket : "mybucket" },
156- storagePath : "foo.mp4" ,
157- want : "https://mybucket.storage.googleapis.com/foo.mp4" ,
158- },
159- {
160- name : "nested path" ,
161- conf : GCPConfig {Bucket : "mybucket" },
162- storagePath : "a/b/c.mp4" ,
163- want : "https://mybucket.storage.googleapis.com/a/b/c.mp4" ,
164- },
165- {
166- name : "storagePath with leading slash" ,
167- conf : GCPConfig {Bucket : "mybucket" },
168- storagePath : "/foo.mp4" ,
169- want : "https://mybucket.storage.googleapis.com/foo.mp4" ,
170- },
171- {
172- name : "space in key" ,
173- conf : GCPConfig {Bucket : "mybucket" },
174- storagePath : "folder/my file.mp4" ,
175- want : "https://mybucket.storage.googleapis.com/folder/my%20file.mp4" ,
176- },
177- {
178- name : "unicode in key" ,
179- conf : GCPConfig {Bucket : "mybucket" },
180- storagePath : "café/résumé.mp4" ,
181- want : "https://mybucket.storage.googleapis.com/caf%C3%A9/r%C3%A9sum%C3%A9.mp4" ,
182- },
183- }
184- for _ , tc := range cases {
185- s := & gcpStorage {conf : & tc .conf }
186- got := s .location (tc .storagePath )
187- require .Equal (t , tc .want , got , tc .name )
188- requireWellFormedHTTPLocation (t , got , tc .name )
189- }
190- }
191-
192- func TestS3Location (t * testing.T ) {
193- cases := []struct {
194- name string
195- conf S3Config
196- storagePath string
197- want string
198- }{
199- {
200- name : "vhost default endpoint" ,
201- conf : S3Config {Bucket : "mybucket" },
202- storagePath : "foo.mp4" ,
203- want : "https://mybucket.s3.amazonaws.com/foo.mp4" ,
204- },
205- {
206- name : "vhost custom endpoint without scheme" ,
207- conf : S3Config {Bucket : "mybucket" , Endpoint : "s3.example.com" },
208- storagePath : "foo.mp4" ,
209- want : "https://mybucket.s3.example.com/foo.mp4" ,
210- },
211- {
212- name : "vhost custom endpoint with https://" ,
213- conf : S3Config {Bucket : "mybucket" , Endpoint : "https://s3.example.com" },
214- storagePath : "foo.mp4" ,
215- want : "https://mybucket.s3.example.com/foo.mp4" ,
216- },
217- {
218- name : "vhost custom endpoint with http://" ,
219- conf : S3Config {Bucket : "mybucket" , Endpoint : "http://s3.example.com" },
220- storagePath : "foo.mp4" ,
221- want : "https://mybucket.s3.example.com/foo.mp4" ,
222- },
223- {
224- name : "vhost nested path" ,
225- conf : S3Config {Bucket : "mybucket" },
226- storagePath : "a/b/c.mp4" ,
227- want : "https://mybucket.s3.amazonaws.com/a/b/c.mp4" ,
228- },
229- {
230- name : "vhost storagePath with leading slash" ,
231- conf : S3Config {Bucket : "mybucket" },
232- storagePath : "/foo.mp4" ,
233- want : "https://mybucket.s3.amazonaws.com/foo.mp4" ,
234- },
235- {
236- name : "vhost space in key" ,
237- conf : S3Config {Bucket : "mybucket" },
238- storagePath : "folder/my file.mp4" ,
239- want : "https://mybucket.s3.amazonaws.com/folder/my%20file.mp4" ,
240- },
241- {
242- name : "vhost unicode in key" ,
243- conf : S3Config {Bucket : "mybucket" },
244- storagePath : "café/résumé.mp4" ,
245- want : "https://mybucket.s3.amazonaws.com/caf%C3%A9/r%C3%A9sum%C3%A9.mp4" ,
246- },
247- {
248- name : "force path style default endpoint" ,
249- conf : S3Config {Bucket : "mybucket" , ForcePathStyle : true },
250- storagePath : "foo.mp4" ,
251- want : "https://s3.amazonaws.com/mybucket/foo.mp4" ,
252- },
253- {
254- name : "force path style custom endpoint" ,
255- conf : S3Config {Bucket : "mybucket" , Endpoint : "https://minio.example.com" , ForcePathStyle : true },
256- storagePath : "foo.mp4" ,
257- want : "https://minio.example.com/mybucket/foo.mp4" ,
258- },
259- {
260- name : "force path style nested" ,
261- conf : S3Config {Bucket : "mybucket" , ForcePathStyle : true },
262- storagePath : "a/b/c.mp4" ,
263- want : "https://s3.amazonaws.com/mybucket/a/b/c.mp4" ,
264- },
265- {
266- name : "force path style storagePath with leading slash" ,
267- conf : S3Config {Bucket : "mybucket" , ForcePathStyle : true },
268- storagePath : "/foo.mp4" ,
269- want : "https://s3.amazonaws.com/mybucket/foo.mp4" ,
270- },
271- }
272- for _ , tc := range cases {
273- s := & s3Storage {conf : & tc .conf }
274- got := s .location (tc .storagePath )
275- require .Equal (t , tc .want , got , tc .name )
276- requireWellFormedHTTPLocation (t , got , tc .name )
277- }
278- }
279-
280- func TestLocalLocation (t * testing.T ) {
281- cases := []struct {
282- name string
283- storageDir string
284- storagePath string
285- want string
286- }{
287- {
288- name : "normal" ,
289- storageDir : "/var/storage" ,
290- storagePath : "foo.mp4" ,
291- want : "/var/storage/foo.mp4" ,
292- },
293- {
294- name : "nested path" ,
295- storageDir : "/var/storage" ,
296- storagePath : "a/b/c.mp4" ,
297- want : "/var/storage/a/b/c.mp4" ,
298- },
299- {
300- name : "storagePath with leading slash" ,
301- storageDir : "/var/storage" ,
302- storagePath : "/foo.mp4" ,
303- want : "/var/storage/foo.mp4" ,
304- },
305- {
306- name : "storageDir with trailing slash" ,
307- storageDir : "/var/storage/" ,
308- storagePath : "foo.mp4" ,
309- want : "/var/storage/foo.mp4" ,
310- },
311- }
312- for _ , tc := range cases {
313- u := & localUploader {StorageDir : tc .storageDir }
314- require .Equal (t , tc .want , u .location (tc .storagePath ))
315- }
316- }
317-
31888// requireWellFormedHTTPLocation verifies an https:// location URL is parseable,
31989// uses the https scheme, has a non-empty host, and contains no accidental
32090// double-slashes in its path (the original Azure bug).
0 commit comments