boot: getPath() should take care of simple directory exports. (#3122)

fixes #3120
This commit is contained in:
Krishna Srinivas 2016-10-29 01:38:56 +05:30 committed by Harshavardhana
parent 6a57f2c1f0
commit 79b98b5c25
2 changed files with 42 additions and 39 deletions

View File

@ -165,12 +165,16 @@ func getPath(ep *url.URL) string {
var diskPath string
// For windows ep.Path is usually empty
if runtime.GOOS == "windows" {
// For full URLs windows drive is part of URL path.
// Eg: http://ip:port/C:\mydrive
if ep.Scheme == "http" || ep.Scheme == "https" {
switch ep.Scheme {
case "":
// Eg. "minio server .\export"
diskPath = ep.Path
case "http", "https":
// For full URLs windows drive is part of URL path.
// Eg: http://ip:port/C:\mydrive
// For windows trim off the preceding "/".
diskPath = ep.Path[1:]
} else {
default:
// For the rest url splits drive letter into
// Scheme contruct the disk path back.
diskPath = ep.Scheme + ":" + ep.Opaque

View File

@ -17,7 +17,6 @@
package cmd
import (
"net/url"
"runtime"
"sync"
"testing"
@ -100,51 +99,51 @@ func TestHouseKeeping(t *testing.T) {
}
}
// Test constructing the final path.
// Test getPath() - the path that needs to be passed to newPosix()
func TestGetPath(t *testing.T) {
var testCases []struct {
ep *url.URL
path string
epStr string
path string
}
if runtime.GOOS != "windows" {
if runtime.GOOS == "windows" {
testCases = []struct {
ep *url.URL
path string
epStr string
path string
}{
{
ep: nil,
path: "",
},
{
ep: &url.URL{Path: "/test1"},
path: "/test1",
},
{"\\export", "\\export"},
{"D:\\export", "d:\\export"},
{"D:\\", "d:\\"},
{"D:", "d:"},
{"\\", "\\"},
{"http://localhost/d:/export", "d:/export"},
{"https://localhost/d:/export", "d:/export"},
}
} else {
testCases = []struct {
ep *url.URL
path string
epStr string
path string
}{
{
ep: nil,
path: "",
},
{
ep: &url.URL{Opaque: "\\test1", Scheme: "C"},
path: "C:\\test1",
},
{
ep: &url.URL{Scheme: "http", Path: "/C:\\test1"},
path: "C:\\test1",
},
{"/export", "/export"},
{"http://localhost/export", "/export"},
{"https://localhost/export", "/export"},
}
}
// Validate all the test cases.
for i, testCase := range testCases {
path := getPath(testCase.ep)
if path != testCase.path {
t.Fatalf("Test: %d Expected path %s, got %s", i+1, testCase.path, path)
testCasesCommon := []struct {
epStr string
path string
}{
{"export", "export"},
}
testCases = append(testCases, testCasesCommon...)
for i, test := range testCases {
eps, err := parseStorageEndpoints([]string{test.epStr})
if err != nil {
t.Errorf("Test %d: %s - %s", i+1, test.epStr, err)
continue
}
path := getPath(eps[0])
if path != test.path {
t.Errorf("Test %d: For endpoing %s, getPath() failed, got: %s, expected: %s,", i+1, test.epStr, path, test.path)
}
}
}