Add S3 Scheme as valid URL Scheme (#483)

* Add s3 Scheme as valid URL Scheme

* Merge from Master

* Remove Test Case and fix Error

* Add invalid Test Case

* add valid s3 Test Case for good measure

* Improve Speed and Resource Handling
This commit is contained in:
Stefan Benten 2018-10-16 21:50:37 +02:00 committed by GitHub
parent bcd18a44bc
commit 1e569e3d4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -12,7 +12,11 @@ import (
"strings"
)
const storjScheme = "sj"
// Create a set
var storjScheme = map[string]struct{}{
"sj": {},
"s3": {},
}
// FPath is an OS independently path handling structure
type FPath struct {
@ -44,7 +48,7 @@ func New(p string) (FPath, error) {
return fp, nil
}
if u.Scheme != storjScheme {
if _, validScheme := storjScheme[u.Scheme]; !validScheme {
return fp, fmt.Errorf("unsupported URL scheme: %s, use format sj://bucket/", u.Scheme)
}

View File

@ -69,6 +69,13 @@ func TestStorjURL(t *testing.T) {
base: "myfile",
joint: "myfolder/myfile/suffix",
},
{
url: "s3:////mybucket///myfolder///myfile",
bucket: "mybucket",
path: "myfolder/myfile",
base: "myfile",
joint: "myfolder/myfile/suffix",
},
} {
errTag := fmt.Sprintf("Test case #%d", i)
@ -93,7 +100,7 @@ func TestInvalidStorjURL(t *testing.T) {
"sj://mybucket:8080/",
"sj:///mybucket:8080/",
"sj:////mybucket:8080/",
"s3://mybucket/myfolder/myfile",
"http://bucket/file.txt",
} {
errTag := fmt.Sprintf("Test case #%d", i)
_, err := New(tt)