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:
parent
bcd18a44bc
commit
1e569e3d4d
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user