You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.7 KiB
107 lines
2.7 KiB
9 years ago
|
// +build windows
|
||
|
|
||
|
/*
|
||
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"os"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
9 years ago
|
// Test if various paths work as expected when converted to UNC form
|
||
9 years ago
|
func TestUNCPaths(t *testing.T) {
|
||
|
var testCases = []struct {
|
||
|
objName string
|
||
|
pass bool
|
||
|
}{
|
||
|
{"/abcdef", true},
|
||
|
{"/a/b/c/d/e/f/g", true},
|
||
|
{string(bytes.Repeat([]byte("界"), 85)), true},
|
||
9 years ago
|
// Each path component must be <= 255 bytes long.
|
||
9 years ago
|
{string(bytes.Repeat([]byte("界"), 100)), false},
|
||
8 years ago
|
{`/p/q/r/s/t`, true},
|
||
9 years ago
|
}
|
||
9 years ago
|
// Instantiate posix object to manage a disk
|
||
9 years ago
|
var err error
|
||
|
err = os.Mkdir("c:\\testdisk", 0700)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
9 years ago
|
// Cleanup on exit of test
|
||
9 years ago
|
defer os.RemoveAll("c:\\testdisk")
|
||
9 years ago
|
|
||
9 years ago
|
var fs StorageAPI
|
||
8 years ago
|
fs, err = newPosix(`c:\testdisk`)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
9 years ago
|
// Create volume to use in conjunction with other StorageAPI's file API(s)
|
||
9 years ago
|
err = fs.MakeVol("voldir")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
for _, test := range testCases {
|
||
|
err = fs.AppendFile("voldir", test.objName, []byte("hello"))
|
||
|
if err != nil && test.pass {
|
||
|
t.Error(err)
|
||
|
} else if err == nil && !test.pass {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
fs.DeleteFile("voldir", test.objName)
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// Test to validate posix behaviour on windows when a non-final path component is a file.
|
||
9 years ago
|
func TestUNCPathENOTDIR(t *testing.T) {
|
||
|
var err error
|
||
9 years ago
|
// Instantiate posix object to manage a disk
|
||
9 years ago
|
err = os.Mkdir("c:\\testdisk", 0700)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
9 years ago
|
// Cleanup on exit of test
|
||
9 years ago
|
defer os.RemoveAll("c:\\testdisk")
|
||
8 years ago
|
|
||
9 years ago
|
var fs StorageAPI
|
||
8 years ago
|
fs, err = newPosix(`c:\testdisk`)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
9 years ago
|
// Create volume to use in conjunction with other StorageAPI's file API(s)
|
||
9 years ago
|
err = fs.MakeVol("voldir")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
err = fs.AppendFile("voldir", "/file", []byte("hello"))
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
9 years ago
|
// Try to create a file that includes a file in its path components.
|
||
|
// In *nix, this returns syscall.ENOTDIR while in windows we receive the following error.
|
||
9 years ago
|
err = fs.AppendFile("voldir", "/file/obj1", []byte("hello"))
|
||
9 years ago
|
if err != errFileAccessDenied {
|
||
|
t.Errorf("expected: %s, got: %s", errFileAccessDenied, err)
|
||
9 years ago
|
}
|
||
|
}
|