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

fixes #3120
master
Krishna Srinivas 8 years ago committed by Harshavardhana
parent 6a57f2c1f0
commit 79b98b5c25
  1. 12
      cmd/object-common.go
  2. 69
      cmd/object-common_test.go

@ -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

@ -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)
}
}
}

Loading…
Cancel
Save