mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
boot: getPath() should take care of simple directory exports. (#3122)
fixes #3120
This commit is contained in:
parent
6a57f2c1f0
commit
79b98b5c25
@ -165,12 +165,16 @@ func getPath(ep *url.URL) string {
|
|||||||
var diskPath string
|
var diskPath string
|
||||||
// For windows ep.Path is usually empty
|
// For windows ep.Path is usually empty
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
// For full URLs windows drive is part of URL path.
|
switch ep.Scheme {
|
||||||
// Eg: http://ip:port/C:\mydrive
|
case "":
|
||||||
if ep.Scheme == "http" || ep.Scheme == "https" {
|
// 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 "/".
|
// For windows trim off the preceding "/".
|
||||||
diskPath = ep.Path[1:]
|
diskPath = ep.Path[1:]
|
||||||
} else {
|
default:
|
||||||
// For the rest url splits drive letter into
|
// For the rest url splits drive letter into
|
||||||
// Scheme contruct the disk path back.
|
// Scheme contruct the disk path back.
|
||||||
diskPath = ep.Scheme + ":" + ep.Opaque
|
diskPath = ep.Scheme + ":" + ep.Opaque
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"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) {
|
func TestGetPath(t *testing.T) {
|
||||||
var testCases []struct {
|
var testCases []struct {
|
||||||
ep *url.URL
|
epStr string
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
testCases = []struct {
|
testCases = []struct {
|
||||||
ep *url.URL
|
epStr string
|
||||||
path string
|
path string
|
||||||
}{
|
}{
|
||||||
{
|
{"\\export", "\\export"},
|
||||||
ep: nil,
|
{"D:\\export", "d:\\export"},
|
||||||
path: "",
|
{"D:\\", "d:\\"},
|
||||||
},
|
{"D:", "d:"},
|
||||||
{
|
{"\\", "\\"},
|
||||||
ep: &url.URL{Path: "/test1"},
|
{"http://localhost/d:/export", "d:/export"},
|
||||||
path: "/test1",
|
{"https://localhost/d:/export", "d:/export"},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
testCases = []struct {
|
testCases = []struct {
|
||||||
ep *url.URL
|
epStr string
|
||||||
path string
|
path string
|
||||||
}{
|
}{
|
||||||
{
|
{"/export", "/export"},
|
||||||
ep: nil,
|
{"http://localhost/export", "/export"},
|
||||||
path: "",
|
{"https://localhost/export", "/export"},
|
||||||
},
|
|
||||||
{
|
|
||||||
ep: &url.URL{Opaque: "\\test1", Scheme: "C"},
|
|
||||||
path: "C:\\test1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ep: &url.URL{Scheme: "http", Path: "/C:\\test1"},
|
|
||||||
path: "C:\\test1",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
testCasesCommon := []struct {
|
||||||
// Validate all the test cases.
|
epStr string
|
||||||
for i, testCase := range testCases {
|
path string
|
||||||
path := getPath(testCase.ep)
|
}{
|
||||||
if path != testCase.path {
|
{"export", "export"},
|
||||||
t.Fatalf("Test: %d Expected path %s, got %s", i+1, testCase.path, path)
|
}
|
||||||
|
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…
Reference in New Issue
Block a user