|
|
@ -200,48 +200,52 @@ func TestParseStorageEndpoints(t *testing.T) { |
|
|
|
// Test check endpoints syntax function for syntax verification
|
|
|
|
// Test check endpoints syntax function for syntax verification
|
|
|
|
// across various scenarios of inputs.
|
|
|
|
// across various scenarios of inputs.
|
|
|
|
func TestCheckEndpointsSyntax(t *testing.T) { |
|
|
|
func TestCheckEndpointsSyntax(t *testing.T) { |
|
|
|
var testCases []string |
|
|
|
successCases := []string{ |
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
|
|
|
|
testCases = []string{ |
|
|
|
|
|
|
|
"\\export", |
|
|
|
|
|
|
|
"D:\\export", |
|
|
|
|
|
|
|
"D:\\", |
|
|
|
|
|
|
|
"D:", |
|
|
|
|
|
|
|
"\\", |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
testCases = []string{ |
|
|
|
|
|
|
|
"/export", |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
testCasesCommon := []string{ |
|
|
|
|
|
|
|
"export", |
|
|
|
"export", |
|
|
|
|
|
|
|
"/export", |
|
|
|
"http://localhost/export", |
|
|
|
"http://localhost/export", |
|
|
|
"https://localhost/export", |
|
|
|
"https://localhost/export", |
|
|
|
} |
|
|
|
} |
|
|
|
testCases = append(testCases, testCasesCommon...) |
|
|
|
|
|
|
|
for _, disk := range testCases { |
|
|
|
failureCases := []string{ |
|
|
|
|
|
|
|
"/", |
|
|
|
|
|
|
|
"http://localhost", |
|
|
|
|
|
|
|
"http://localhost/", |
|
|
|
|
|
|
|
"ftp://localhost/export", |
|
|
|
|
|
|
|
"server:/export", |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
|
|
|
|
successCases = append(successCases, |
|
|
|
|
|
|
|
`\export`, |
|
|
|
|
|
|
|
`D:\export`, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
failureCases = append(failureCases, |
|
|
|
|
|
|
|
"D:", |
|
|
|
|
|
|
|
`D:\`, |
|
|
|
|
|
|
|
`\`, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, disk := range successCases { |
|
|
|
eps, err := parseStorageEndpoints([]string{disk}) |
|
|
|
eps, err := parseStorageEndpoints([]string{disk}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Unable to parse %s, error %s", disk, err) |
|
|
|
t.Fatalf("Unable to parse %s, error %s", disk, err) |
|
|
|
} |
|
|
|
} |
|
|
|
if err = checkEndpointsSyntax(eps, []string{disk}); err != nil { |
|
|
|
if err = checkEndpointsSyntax(eps, []string{disk}); err != nil { |
|
|
|
t.Errorf("Invalid endpoints %s", err) |
|
|
|
t.Errorf("expected: <nil>, got: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
eps, err := parseStorageEndpoints([]string{"/"}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
for _, disk := range failureCases { |
|
|
|
t.Fatalf("Unable to parse /, error %s", err) |
|
|
|
eps, err := parseStorageEndpoints([]string{disk}) |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
if err = checkEndpointsSyntax(eps, []string{"/"}); err == nil { |
|
|
|
t.Fatalf("Unable to parse %s, error %s", disk, err) |
|
|
|
t.Error("Should fail, passed instead") |
|
|
|
} |
|
|
|
} |
|
|
|
if err = checkEndpointsSyntax(eps, []string{disk}); err == nil { |
|
|
|
eps, err = parseStorageEndpoints([]string{"http://localhost/"}) |
|
|
|
t.Errorf("expected: <error>, got: <nil>") |
|
|
|
if err != nil { |
|
|
|
} |
|
|
|
t.Fatalf("Unable to parse http://localhost/, error %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err = checkEndpointsSyntax(eps, []string{"http://localhost/"}); err == nil { |
|
|
|
|
|
|
|
t.Error("Should fail, passed instead") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|