mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
fs: Re-implement object layer to remember the fd (#3509)
This patch re-writes FS backend to support shared backend sharing locks for safe concurrent access across multiple servers.
This commit is contained in:
@@ -43,8 +43,8 @@ func newPosixTestSetup() (StorageAPI, string, error) {
|
||||
return posixStorage, diskPath, nil
|
||||
}
|
||||
|
||||
// Tests posix.getDiskInfo()
|
||||
func TestGetDiskInfo(t *testing.T) {
|
||||
// TestPosixs posix.getDiskInfo()
|
||||
func TestPosixGetDiskInfo(t *testing.T) {
|
||||
path, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create a temporary directory, %s", err)
|
||||
@@ -67,8 +67,8 @@ func TestGetDiskInfo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestReadAll - Tests the functionality implemented by posix ReadAll storage API.
|
||||
func TestReadAll(t *testing.T) {
|
||||
// TestPosixReadAll - TestPosixs the functionality implemented by posix ReadAll storage API.
|
||||
func TestPosixReadAll(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -91,27 +91,27 @@ func TestReadAll(t *testing.T) {
|
||||
t.Fatalf("Unable to create a file \"as-file-parent\", %s", err)
|
||||
}
|
||||
|
||||
// Testcases to validate different conditions for ReadAll API.
|
||||
// TestPosixcases to validate different conditions for ReadAll API.
|
||||
testCases := []struct {
|
||||
volume string
|
||||
path string
|
||||
err error
|
||||
}{
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
// Validate volume does not exist.
|
||||
{
|
||||
volume: "i-dont-exist",
|
||||
path: "",
|
||||
err: errVolumeNotFound,
|
||||
},
|
||||
// Test case - 2.
|
||||
// TestPosix case - 2.
|
||||
// Validate bad condition file does not exist.
|
||||
{
|
||||
volume: "exists",
|
||||
path: "as-file-not-found",
|
||||
err: errFileNotFound,
|
||||
},
|
||||
// Test case - 3.
|
||||
// TestPosix case - 3.
|
||||
// Validate bad condition file exists as prefix/directory and
|
||||
// we are attempting to read it.
|
||||
{
|
||||
@@ -119,21 +119,21 @@ func TestReadAll(t *testing.T) {
|
||||
path: "as-directory",
|
||||
err: errFileNotFound,
|
||||
},
|
||||
// Test case - 4.
|
||||
// TestPosix case - 4.
|
||||
{
|
||||
volume: "exists",
|
||||
path: "as-file-parent/as-file",
|
||||
err: errFileNotFound,
|
||||
},
|
||||
// Test case - 5.
|
||||
// TestPosix case - 5.
|
||||
// Validate the good condition file exists and we are able to read it.
|
||||
{
|
||||
volume: "exists",
|
||||
path: "as-file",
|
||||
err: nil,
|
||||
},
|
||||
// Test case - 6.
|
||||
// Test case with invalid volume name.
|
||||
// TestPosix case - 6.
|
||||
// TestPosix case with invalid volume name.
|
||||
{
|
||||
volume: "ab",
|
||||
path: "as-file",
|
||||
@@ -146,15 +146,15 @@ func TestReadAll(t *testing.T) {
|
||||
for i, testCase := range testCases {
|
||||
dataRead, err = posixStorage.ReadAll(testCase.volume, testCase.path)
|
||||
if err != testCase.err {
|
||||
t.Fatalf("Test %d: Expected err \"%s\", got err \"%s\"", i+1, testCase.err, err)
|
||||
t.Fatalf("TestPosix %d: Expected err \"%s\", got err \"%s\"", i+1, testCase.err, err)
|
||||
}
|
||||
if err == nil {
|
||||
if string(dataRead) != string([]byte("Hello, World")) {
|
||||
t.Errorf("Test %d: Expected the data read to be \"%s\", but instead got \"%s\"", i+1, "Hello, World", string(dataRead))
|
||||
t.Errorf("TestPosix %d: Expected the data read to be \"%s\", but instead got \"%s\"", i+1, "Hello, World", string(dataRead))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Testing for faulty disk.
|
||||
// TestPosixing for faulty disk.
|
||||
// Setting ioErrCount > maxAllowedIOError.
|
||||
if posixType, ok := posixStorage.(*posix); ok {
|
||||
// setting the io error count from as specified in the test case.
|
||||
@@ -168,8 +168,8 @@ func TestReadAll(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewPosix all the cases handled in posix storage layer initialization.
|
||||
func TestNewPosix(t *testing.T) {
|
||||
// TestPosixNewPosix all the cases handled in posix storage layer initialization.
|
||||
func TestPosixNewPosix(t *testing.T) {
|
||||
// Temporary dir name.
|
||||
tmpDirName := globalTestTmpDir + "/" + "minio-" + nextSuffix()
|
||||
// Temporary file name.
|
||||
@@ -207,14 +207,14 @@ func TestNewPosix(t *testing.T) {
|
||||
// Initialize a new posix layer.
|
||||
_, err := newPosix(testCase.name)
|
||||
if err != testCase.err {
|
||||
t.Fatalf("Test %d failed wanted: %s, got: %s", i+1, err, testCase.err)
|
||||
t.Fatalf("TestPosix %d failed wanted: %s, got: %s", i+1, err, testCase.err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMakeVol - Test validate the logic for creation of new posix volume.
|
||||
// TestPosixMakeVol - TestPosix validate the logic for creation of new posix volume.
|
||||
// Asserts the failures too against the expected failures.
|
||||
func TestMakeVol(t *testing.T) {
|
||||
func TestPosixMakeVol(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -237,35 +237,35 @@ func TestMakeVol(t *testing.T) {
|
||||
ioErrCount int
|
||||
expectedErr error
|
||||
}{
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
// A valid case, volume creation is expected to succeed.
|
||||
{
|
||||
volName: "success-vol",
|
||||
ioErrCount: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 2.
|
||||
// TestPosix case - 2.
|
||||
// Case where a file exists by the name of the volume to be created.
|
||||
{
|
||||
volName: "vol-as-file",
|
||||
ioErrCount: 0,
|
||||
expectedErr: errVolumeExists,
|
||||
},
|
||||
// Test case - 3.
|
||||
// TestPosix case - 3.
|
||||
{
|
||||
volName: "existing-vol",
|
||||
ioErrCount: 0,
|
||||
expectedErr: errVolumeExists,
|
||||
},
|
||||
// Test case - 4.
|
||||
// TestPosix case - 4.
|
||||
// IO error > maxAllowedIOError, should fail with errFaultyDisk.
|
||||
{
|
||||
volName: "vol",
|
||||
ioErrCount: 6,
|
||||
expectedErr: errFaultyDisk,
|
||||
},
|
||||
// Test case - 5.
|
||||
// Test case with invalid volume name.
|
||||
// TestPosix case - 5.
|
||||
// TestPosix case with invalid volume name.
|
||||
{
|
||||
volName: "ab",
|
||||
ioErrCount: 0,
|
||||
@@ -281,11 +281,11 @@ func TestMakeVol(t *testing.T) {
|
||||
t.Errorf("Expected the StorageAPI to be of type *posix")
|
||||
}
|
||||
if err := posixStorage.MakeVol(testCase.volName); err != testCase.expectedErr {
|
||||
t.Fatalf("Test %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
t.Fatalf("TestPosix %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Test for permission denied.
|
||||
// TestPosix for permission denied.
|
||||
if runtime.GOOS != "windows" {
|
||||
// Initialize posix storage layer for permission denied error.
|
||||
posix, err := newPosix("/usr")
|
||||
@@ -299,8 +299,8 @@ func TestMakeVol(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestDeleteVol - Validates the expected behaviour of posix.DeleteVol for various cases.
|
||||
func TestDeleteVol(t *testing.T) {
|
||||
// TestPosixDeleteVol - Validates the expected behaviour of posix.DeleteVol for various cases.
|
||||
func TestPosixDeleteVol(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -313,7 +313,7 @@ func TestDeleteVol(t *testing.T) {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
// Test failure cases.
|
||||
// TestPosix failure cases.
|
||||
vol := slashpath.Join(path, "nonempty-vol")
|
||||
if err = os.Mkdir(vol, 0777); err != nil {
|
||||
t.Fatalf("Unable to create directory, %s", err)
|
||||
@@ -327,35 +327,35 @@ func TestDeleteVol(t *testing.T) {
|
||||
ioErrCount int
|
||||
expectedErr error
|
||||
}{
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
// A valida case. Empty vol, should be possible to delete.
|
||||
{
|
||||
volName: "success-vol",
|
||||
ioErrCount: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 2.
|
||||
// TestPosix case - 2.
|
||||
// volume is non-existent.
|
||||
{
|
||||
volName: "nonexistent-vol",
|
||||
ioErrCount: 0,
|
||||
expectedErr: errVolumeNotFound,
|
||||
},
|
||||
// Test case - 3.
|
||||
// TestPosix case - 3.
|
||||
// It shouldn't be possible to delete an non-empty volume, validating the same.
|
||||
{
|
||||
volName: "nonempty-vol",
|
||||
ioErrCount: 0,
|
||||
expectedErr: errVolumeNotEmpty,
|
||||
},
|
||||
// Test case - 4.
|
||||
// TestPosix case - 4.
|
||||
// IO error > maxAllowedIOError, should fail with errFaultyDisk.
|
||||
{
|
||||
volName: "my-disk",
|
||||
ioErrCount: 6,
|
||||
expectedErr: errFaultyDisk,
|
||||
},
|
||||
// Test case - 5.
|
||||
// TestPosix case - 5.
|
||||
// Invalid volume name.
|
||||
{
|
||||
volName: "ab",
|
||||
@@ -372,11 +372,11 @@ func TestDeleteVol(t *testing.T) {
|
||||
t.Errorf("Expected the StorageAPI to be of type *posix")
|
||||
}
|
||||
if err = posixStorage.DeleteVol(testCase.volName); err != testCase.expectedErr {
|
||||
t.Fatalf("Test: %d, expected: %s, got: %s", i+1, testCase.expectedErr, err)
|
||||
t.Fatalf("TestPosix: %d, expected: %s, got: %s", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Test for permission denied.
|
||||
// TestPosix for permission denied.
|
||||
if runtime.GOOS != "windows" {
|
||||
// Initialize posix storage layer for permission denied error.
|
||||
posixStorage, err = newPosix("/usr")
|
||||
@@ -396,7 +396,7 @@ func TestDeleteVol(t *testing.T) {
|
||||
// removing the disk, used to recreate disk not found error.
|
||||
removeAll(diskPath)
|
||||
|
||||
// Test for delete on an removed disk.
|
||||
// TestPosix for delete on an removed disk.
|
||||
// should fail with disk not found.
|
||||
err = posixDeletedStorage.DeleteVol("Del-Vol")
|
||||
if err != errDiskNotFound {
|
||||
@@ -404,8 +404,8 @@ func TestDeleteVol(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatVol - Tests validate the volume info returned by posix.StatVol() for various inputs.
|
||||
func TestStatVol(t *testing.T) {
|
||||
// TestPosixStatVol - TestPosixs validate the volume info returned by posix.StatVol() for various inputs.
|
||||
func TestPosixStatVol(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -423,25 +423,25 @@ func TestStatVol(t *testing.T) {
|
||||
ioErrCount int
|
||||
expectedErr error
|
||||
}{
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
{
|
||||
volName: "success-vol",
|
||||
ioErrCount: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 2.
|
||||
// TestPosix case - 2.
|
||||
{
|
||||
volName: "nonexistent-vol",
|
||||
ioErrCount: 0,
|
||||
expectedErr: errVolumeNotFound,
|
||||
},
|
||||
// Test case - 3.
|
||||
// TestPosix case - 3.
|
||||
{
|
||||
volName: "success-vol",
|
||||
ioErrCount: 6,
|
||||
expectedErr: errFaultyDisk,
|
||||
},
|
||||
// Test case - 4.
|
||||
// TestPosix case - 4.
|
||||
{
|
||||
volName: "ab",
|
||||
ioErrCount: 0,
|
||||
@@ -460,12 +460,12 @@ func TestStatVol(t *testing.T) {
|
||||
}
|
||||
volInfo, err = posixStorage.StatVol(testCase.volName)
|
||||
if err != testCase.expectedErr {
|
||||
t.Fatalf("Test case : %d, Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
t.Fatalf("TestPosix case : %d, Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
if volInfo.Name != volInfo.Name {
|
||||
t.Errorf("Test case %d: Expected the volume name to be \"%s\", instead found \"%s\"", i+1, volInfo.Name, volInfo.Name)
|
||||
t.Errorf("TestPosix case %d: Expected the volume name to be \"%s\", instead found \"%s\"", i+1, volInfo.Name, volInfo.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,7 +477,7 @@ func TestStatVol(t *testing.T) {
|
||||
// removing the disk, used to recreate disk not found error.
|
||||
removeAll(diskPath)
|
||||
|
||||
// Test for delete on an removed disk.
|
||||
// TestPosix for delete on an removed disk.
|
||||
// should fail with disk not found.
|
||||
_, err = posixDeletedStorage.StatVol("Stat vol")
|
||||
if err != errDiskNotFound {
|
||||
@@ -485,8 +485,8 @@ func TestStatVol(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestListVols - Validates the result and the error output for posix volume listing functionality posix.ListVols().
|
||||
func TestListVols(t *testing.T) {
|
||||
// TestPosixListVols - Validates the result and the error output for posix volume listing functionality posix.ListVols().
|
||||
func TestPosixListVols(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -494,14 +494,14 @@ func TestListVols(t *testing.T) {
|
||||
}
|
||||
|
||||
var volInfo []VolInfo
|
||||
// Test empty list vols.
|
||||
// TestPosix empty list vols.
|
||||
if volInfo, err = posixStorage.ListVols(); err != nil {
|
||||
t.Fatalf("expected: <nil>, got: %s", err)
|
||||
} else if len(volInfo) != 0 {
|
||||
t.Fatalf("expected: [], got: %s", volInfo)
|
||||
}
|
||||
|
||||
// Test non-empty list vols.
|
||||
// TestPosix non-empty list vols.
|
||||
if err = posixStorage.MakeVol("success-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
@@ -538,8 +538,8 @@ func TestListVols(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestPosixListDir - Tests validate the directory listing functionality provided by posix.ListDir .
|
||||
func TestPosixListDir(t *testing.T) {
|
||||
// TestPosixPosixListDir - TestPosixs validate the directory listing functionality provided by posix.ListDir .
|
||||
func TestPosixPosixListDir(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -573,7 +573,7 @@ func TestPosixListDir(t *testing.T) {
|
||||
expectedListDir []string
|
||||
expectedErr error
|
||||
}{
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
// valid case with existing volume and file to delete.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
@@ -582,7 +582,7 @@ func TestPosixListDir(t *testing.T) {
|
||||
expectedListDir: []string{"def/", "xyz/"},
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
// valid case with existing volume and file to delete.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
@@ -591,7 +591,7 @@ func TestPosixListDir(t *testing.T) {
|
||||
expectedListDir: []string{"ghi/"},
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
// valid case with existing volume and file to delete.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
@@ -600,31 +600,31 @@ func TestPosixListDir(t *testing.T) {
|
||||
expectedListDir: []string{"success-file"},
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 2.
|
||||
// TestPosix case - 2.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "abcdef",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileNotFound,
|
||||
},
|
||||
// Test case - 3.
|
||||
// Test case with invalid volume name.
|
||||
// TestPosix case - 3.
|
||||
// TestPosix case with invalid volume name.
|
||||
{
|
||||
srcVol: "ab",
|
||||
srcPath: "success-file",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errInvalidArgument,
|
||||
},
|
||||
// Test case - 4.
|
||||
// Test case with io error count > max limit.
|
||||
// TestPosix case - 4.
|
||||
// TestPosix case with io error count > max limit.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "success-file",
|
||||
ioErrCnt: 6,
|
||||
expectedErr: errFaultyDisk,
|
||||
},
|
||||
// Test case - 5.
|
||||
// Test case with non existent volume.
|
||||
// TestPosix case - 5.
|
||||
// TestPosix case with non existent volume.
|
||||
{
|
||||
srcVol: "non-existent-vol",
|
||||
srcPath: "success-file",
|
||||
@@ -644,18 +644,18 @@ func TestPosixListDir(t *testing.T) {
|
||||
}
|
||||
dirList, err = posixStorage.ListDir(testCase.srcVol, testCase.srcPath)
|
||||
if err != testCase.expectedErr {
|
||||
t.Fatalf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
if err == nil {
|
||||
for _, expected := range testCase.expectedListDir {
|
||||
if !strings.Contains(strings.Join(dirList, ","), expected) {
|
||||
t.Errorf("Test case %d: Expected the directory listing to be \"%v\", but got \"%v\"", i+1, testCase.expectedListDir, dirList)
|
||||
t.Errorf("TestPosix case %d: Expected the directory listing to be \"%v\", but got \"%v\"", i+1, testCase.expectedListDir, dirList)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test for permission denied.
|
||||
// TestPosix for permission denied.
|
||||
if runtime.GOOS != "windows" {
|
||||
// Initialize posix storage layer for permission denied error.
|
||||
posixStorage, err = newPosix("/usr")
|
||||
@@ -668,7 +668,7 @@ func TestPosixListDir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test for delete on an removed disk.
|
||||
// TestPosix for delete on an removed disk.
|
||||
// should fail with disk not found.
|
||||
err = posixDeletedStorage.DeleteFile("del-vol", "my-file")
|
||||
if err != errDiskNotFound {
|
||||
@@ -676,8 +676,8 @@ func TestPosixListDir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestDeleteFile - Series of test cases construct valid and invalid input data and validates the result and the error response.
|
||||
func TestDeleteFile(t *testing.T) {
|
||||
// TestPosixDeleteFile - Series of test cases construct valid and invalid input data and validates the result and the error response.
|
||||
func TestPosixDeleteFile(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -706,7 +706,7 @@ func TestDeleteFile(t *testing.T) {
|
||||
ioErrCnt int
|
||||
expectedErr error
|
||||
}{
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
// valid case with existing volume and file to delete.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
@@ -714,7 +714,7 @@ func TestDeleteFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 2.
|
||||
// TestPosix case - 2.
|
||||
// The file was deleted in the last case, so DeleteFile should fail.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
@@ -722,32 +722,32 @@ func TestDeleteFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileNotFound,
|
||||
},
|
||||
// Test case - 3.
|
||||
// Test case with io error count > max limit.
|
||||
// TestPosix case - 3.
|
||||
// TestPosix case with io error count > max limit.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "success-file",
|
||||
ioErrCnt: 6,
|
||||
expectedErr: errFaultyDisk,
|
||||
},
|
||||
// Test case - 4.
|
||||
// Test case with segment of the volume name > 255.
|
||||
// TestPosix case - 4.
|
||||
// TestPosix case with segment of the volume name > 255.
|
||||
{
|
||||
srcVol: "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
|
||||
srcPath: "success-file",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errInvalidArgument,
|
||||
},
|
||||
// Test case - 5.
|
||||
// Test case with non-existent volume.
|
||||
// TestPosix case - 5.
|
||||
// TestPosix case with non-existent volume.
|
||||
{
|
||||
srcVol: "non-existent-vol",
|
||||
srcPath: "success-file",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errVolumeNotFound,
|
||||
},
|
||||
// Test case - 6.
|
||||
// Test case with src path segment > 255.
|
||||
// TestPosix case - 6.
|
||||
// TestPosix case with src path segment > 255.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
|
||||
@@ -765,11 +765,11 @@ func TestDeleteFile(t *testing.T) {
|
||||
t.Errorf("Expected the StorageAPI to be of type *posix")
|
||||
}
|
||||
if err = posixStorage.DeleteFile(testCase.srcVol, testCase.srcPath); err != testCase.expectedErr {
|
||||
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
t.Errorf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Test for permission denied.
|
||||
// TestPosix for permission denied.
|
||||
if runtime.GOOS != "windows" {
|
||||
// Initialize posix storage layer for permission denied error.
|
||||
posixStorage, err = newPosix("/usr")
|
||||
@@ -782,7 +782,7 @@ func TestDeleteFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test for delete on an removed disk.
|
||||
// TestPosix for delete on an removed disk.
|
||||
// should fail with disk not found.
|
||||
err = posixDeletedStorage.DeleteFile("del-vol", "my-file")
|
||||
if err != errDiskNotFound {
|
||||
@@ -790,8 +790,8 @@ func TestDeleteFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestReadFile - Tests posix.ReadFile with wide range of cases and asserts the result and error response.
|
||||
func TestReadFile(t *testing.T) {
|
||||
// TestPosixReadFile - TestPosixs posix.ReadFile with wide range of cases and asserts the result and error response.
|
||||
func TestPosixReadFile(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -984,7 +984,7 @@ func TestReadFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test for permission denied.
|
||||
// TestPosix for permission denied.
|
||||
if runtime.GOOS == "linux" {
|
||||
// Initialize posix storage layer for permission denied error.
|
||||
posixStorage, err = newPosix("/")
|
||||
@@ -1000,7 +1000,7 @@ func TestReadFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Testing for faulty disk.
|
||||
// TestPosixing for faulty disk.
|
||||
// setting ioErrCnt to 6.
|
||||
// should fail with errFaultyDisk.
|
||||
if posixType, ok := posixStorage.(*posix); ok {
|
||||
@@ -1017,8 +1017,8 @@ func TestReadFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test posix.AppendFile()
|
||||
func TestAppendFile(t *testing.T) {
|
||||
// TestPosix posix.AppendFile()
|
||||
func TestPosixAppendFile(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -1042,9 +1042,9 @@ func TestAppendFile(t *testing.T) {
|
||||
}{
|
||||
{"myobject", nil},
|
||||
{"path/to/my/object", nil},
|
||||
// Test to append to previously created file.
|
||||
// TestPosix to append to previously created file.
|
||||
{"myobject", nil},
|
||||
// Test to use same path of previously created file.
|
||||
// TestPosix to use same path of previously created file.
|
||||
{"path/to/my/testobject", nil},
|
||||
// One path segment length is 255 chars long.
|
||||
{"path/to/my/object000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", nil},
|
||||
@@ -1074,7 +1074,7 @@ func TestAppendFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test for permission denied.
|
||||
// TestPosix for permission denied.
|
||||
if runtime.GOOS != "windows" {
|
||||
// Initialize posix storage layer for permission denied error.
|
||||
posixStorage, err = newPosix("/usr")
|
||||
@@ -1086,14 +1086,14 @@ func TestAppendFile(t *testing.T) {
|
||||
t.Errorf("expected: Permission error, got: %s", err)
|
||||
}
|
||||
}
|
||||
// Test case with invalid volume name.
|
||||
// TestPosix case with invalid volume name.
|
||||
// A valid volume name should be atleast of size 3.
|
||||
err = posixStorage.AppendFile("bn", "yes", []byte("hello, world"))
|
||||
if err != errInvalidArgument {
|
||||
t.Fatalf("expected: \"Invalid argument error\", got: \"%s\"", err)
|
||||
}
|
||||
|
||||
// Test case with IO error count > max limit.
|
||||
// TestPosix case with IO error count > max limit.
|
||||
|
||||
// setting ioErrCnt to 6.
|
||||
// should fail with errFaultyDisk.
|
||||
@@ -1109,8 +1109,8 @@ func TestAppendFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test posix.PrepareFile()
|
||||
func TestPrepareFile(t *testing.T) {
|
||||
// TestPosix posix.PrepareFile()
|
||||
func TestPosixPrepareFile(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -1133,9 +1133,9 @@ func TestPrepareFile(t *testing.T) {
|
||||
}{
|
||||
{"myobject", nil},
|
||||
{"path/to/my/object", nil},
|
||||
// Test to append to previously created file.
|
||||
// TestPosix to append to previously created file.
|
||||
{"myobject", nil},
|
||||
// Test to use same path of previously created file.
|
||||
// TestPosix to use same path of previously created file.
|
||||
{"path/to/my/testobject", nil},
|
||||
{"object-as-dir", errIsNotRegular},
|
||||
// path segment uses previously uploaded object.
|
||||
@@ -1161,7 +1161,7 @@ func TestPrepareFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test for permission denied.
|
||||
// TestPosix for permission denied.
|
||||
if runtime.GOOS != "windows" {
|
||||
// Initialize posix storage layer for permission denied error.
|
||||
posixStorage, err = newPosix("/usr")
|
||||
@@ -1174,20 +1174,20 @@ func TestPrepareFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test case with invalid file size which should be strictly positive
|
||||
// TestPosix case with invalid file size which should be strictly positive
|
||||
err = posixStorage.PrepareFile("bn", "yes", -3)
|
||||
if err != errInvalidArgument {
|
||||
t.Fatalf("should fail: %v", err)
|
||||
}
|
||||
|
||||
// Test case with invalid volume name.
|
||||
// TestPosix case with invalid volume name.
|
||||
// A valid volume name should be atleast of size 3.
|
||||
err = posixStorage.PrepareFile("bn", "yes", 16)
|
||||
if err != errInvalidArgument {
|
||||
t.Fatalf("expected: \"Invalid argument error\", got: \"%s\"", err)
|
||||
}
|
||||
|
||||
// Test case with IO error count > max limit.
|
||||
// TestPosix case with IO error count > max limit.
|
||||
|
||||
// setting ioErrCnt to 6.
|
||||
// should fail with errFaultyDisk.
|
||||
@@ -1203,8 +1203,8 @@ func TestPrepareFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test posix.RenameFile()
|
||||
func TestRenameFile(t *testing.T) {
|
||||
// TestPosix posix.RenameFile()
|
||||
func TestPosixRenameFile(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -1250,7 +1250,7 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt int
|
||||
expectedErr error
|
||||
}{
|
||||
// Test case - 1.
|
||||
// TestPosix case - 1.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
destVol: "dest-vol",
|
||||
@@ -1259,7 +1259,7 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 2.
|
||||
// TestPosix case - 2.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
destVol: "dest-vol",
|
||||
@@ -1268,8 +1268,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 3.
|
||||
// Test to overwrite destination file.
|
||||
// TestPosix case - 3.
|
||||
// TestPosix to overwrite destination file.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
destVol: "dest-vol",
|
||||
@@ -1278,8 +1278,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 4.
|
||||
// Test case with io error count set to 1.
|
||||
// TestPosix case - 4.
|
||||
// TestPosix case with io error count set to 1.
|
||||
// expected not to fail.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
@@ -1289,8 +1289,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 1,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 5.
|
||||
// Test case with io error count set to maximum allowed count.
|
||||
// TestPosix case - 5.
|
||||
// TestPosix case with io error count set to maximum allowed count.
|
||||
// expected not to fail.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
@@ -1300,8 +1300,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 5,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 6.
|
||||
// Test case with non-existent source file.
|
||||
// TestPosix case - 6.
|
||||
// TestPosix case with non-existent source file.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
destVol: "dest-vol",
|
||||
@@ -1310,8 +1310,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileNotFound,
|
||||
},
|
||||
// Test case - 7.
|
||||
// Test to check failure of source and destination are not same type.
|
||||
// TestPosix case - 7.
|
||||
// TestPosix to check failure of source and destination are not same type.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
destVol: "dest-vol",
|
||||
@@ -1320,8 +1320,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileAccessDenied,
|
||||
},
|
||||
// Test case - 8.
|
||||
// Test to check failure of destination directory exists.
|
||||
// TestPosix case - 8.
|
||||
// TestPosix to check failure of destination directory exists.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
destVol: "dest-vol",
|
||||
@@ -1330,8 +1330,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileAccessDenied,
|
||||
},
|
||||
// Test case - 9.
|
||||
// Test case with io error count is greater than maxAllowedIOError.
|
||||
// TestPosix case - 9.
|
||||
// TestPosix case with io error count is greater than maxAllowedIOError.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
destVol: "dest-vol",
|
||||
@@ -1340,8 +1340,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 6,
|
||||
expectedErr: errFaultyDisk,
|
||||
},
|
||||
// Test case - 10.
|
||||
// Test case with source being a file and destination being a directory.
|
||||
// TestPosix case - 10.
|
||||
// TestPosix case with source being a file and destination being a directory.
|
||||
// Either both have to be files or directories.
|
||||
// Expecting to fail with `errFileAccessDenied`.
|
||||
{
|
||||
@@ -1352,8 +1352,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileAccessDenied,
|
||||
},
|
||||
// Test case - 11.
|
||||
// Test case with non-existent source volume.
|
||||
// TestPosix case - 11.
|
||||
// TestPosix case with non-existent source volume.
|
||||
// Expecting to fail with `errVolumeNotFound`.
|
||||
{
|
||||
srcVol: "src-vol-non-existent",
|
||||
@@ -1363,8 +1363,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errVolumeNotFound,
|
||||
},
|
||||
// Test case - 12.
|
||||
// Test case with non-existent destination volume.
|
||||
// TestPosix case - 12.
|
||||
// TestPosix case with non-existent destination volume.
|
||||
// Expecting to fail with `errVolumeNotFound`.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
@@ -1374,8 +1374,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errVolumeNotFound,
|
||||
},
|
||||
// Test case - 13.
|
||||
// Test case with invalid src volume name. Length should be atleast 3.
|
||||
// TestPosix case - 13.
|
||||
// TestPosix case with invalid src volume name. Length should be atleast 3.
|
||||
// Expecting to fail with `errInvalidArgument`.
|
||||
{
|
||||
srcVol: "ab",
|
||||
@@ -1385,8 +1385,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errInvalidArgument,
|
||||
},
|
||||
// Test case - 14.
|
||||
// Test case with invalid destination volume name. Length should be atleast 3.
|
||||
// TestPosix case - 14.
|
||||
// TestPosix case with invalid destination volume name. Length should be atleast 3.
|
||||
// Expecting to fail with `errInvalidArgument`.
|
||||
{
|
||||
srcVol: "abcd",
|
||||
@@ -1396,8 +1396,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errInvalidArgument,
|
||||
},
|
||||
// Test case - 15.
|
||||
// Test case with invalid destination volume name. Length should be atleast 3.
|
||||
// TestPosix case - 15.
|
||||
// TestPosix case with invalid destination volume name. Length should be atleast 3.
|
||||
// Expecting to fail with `errInvalidArgument`.
|
||||
{
|
||||
srcVol: "abcd",
|
||||
@@ -1407,8 +1407,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errInvalidArgument,
|
||||
},
|
||||
// Test case - 16.
|
||||
// Test case with the parent of the destination being a file.
|
||||
// TestPosix case - 16.
|
||||
// TestPosix case with the parent of the destination being a file.
|
||||
// expected to fail with `errFileAccessDenied`.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
@@ -1418,8 +1418,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileAccessDenied,
|
||||
},
|
||||
// Test case - 17.
|
||||
// Test case with segment of source file name more than 255.
|
||||
// TestPosix case - 17.
|
||||
// TestPosix case with segment of source file name more than 255.
|
||||
// expected not to fail.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
@@ -1429,8 +1429,8 @@ func TestRenameFile(t *testing.T) {
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileNameTooLong,
|
||||
},
|
||||
// Test case - 18.
|
||||
// Test case with segment of destination file name more than 255.
|
||||
// TestPosix case - 18.
|
||||
// TestPosix case with segment of destination file name more than 255.
|
||||
// expected not to fail.
|
||||
{
|
||||
srcVol: "src-vol",
|
||||
@@ -1452,13 +1452,13 @@ func TestRenameFile(t *testing.T) {
|
||||
}
|
||||
|
||||
if err := posixStorage.RenameFile(testCase.srcVol, testCase.srcPath, testCase.destVol, testCase.destPath); err != testCase.expectedErr {
|
||||
t.Fatalf("Test %d: Expected the error to be : \"%v\", got: \"%v\".", i+1, testCase.expectedErr, err)
|
||||
t.Fatalf("TestPosix %d: Expected the error to be : \"%v\", got: \"%v\".", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test posix.StatFile()
|
||||
func TestStatFile(t *testing.T) {
|
||||
// TestPosix posix.StatFile()
|
||||
func TestPosixStatFile(t *testing.T) {
|
||||
// create posix test setup
|
||||
posixStorage, path, err := newPosixTestSetup()
|
||||
if err != nil {
|
||||
@@ -1485,56 +1485,56 @@ func TestStatFile(t *testing.T) {
|
||||
ioErrCnt int
|
||||
expectedErr error
|
||||
}{
|
||||
// Test case - 1.
|
||||
// Test case with valid inputs, expected to pass.
|
||||
// TestPosix case - 1.
|
||||
// TestPosix case with valid inputs, expected to pass.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "success-file",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 2.
|
||||
// Test case with valid inputs, expected to pass.
|
||||
// TestPosix case - 2.
|
||||
// TestPosix case with valid inputs, expected to pass.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "path/to/success-file",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: nil,
|
||||
},
|
||||
// Test case - 3.
|
||||
// Test case with non-existent file.
|
||||
// TestPosix case - 3.
|
||||
// TestPosix case with non-existent file.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "nonexistent-file",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileNotFound,
|
||||
},
|
||||
// Test case - 4.
|
||||
// Test case with non-existent file path.
|
||||
// TestPosix case - 4.
|
||||
// TestPosix case with non-existent file path.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "path/2/success-file",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileNotFound,
|
||||
},
|
||||
// Test case - 5.
|
||||
// Test case with path being a directory.
|
||||
// TestPosix case - 5.
|
||||
// TestPosix case with path being a directory.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "path",
|
||||
ioErrCnt: 0,
|
||||
expectedErr: errFileNotFound,
|
||||
},
|
||||
// Test case - 6.
|
||||
// Test case with io error count > max limit.
|
||||
// TestPosix case - 6.
|
||||
// TestPosix case with io error count > max limit.
|
||||
{
|
||||
srcVol: "success-vol",
|
||||
srcPath: "success-file",
|
||||
ioErrCnt: 6,
|
||||
expectedErr: errFaultyDisk,
|
||||
},
|
||||
// Test case - 7.
|
||||
// Test case with non existent volume.
|
||||
// TestPosix case - 7.
|
||||
// TestPosix case with non existent volume.
|
||||
{
|
||||
srcVol: "non-existent-vol",
|
||||
srcPath: "success-file",
|
||||
@@ -1552,7 +1552,7 @@ func TestStatFile(t *testing.T) {
|
||||
t.Errorf("Expected the StorageAPI to be of type *posix")
|
||||
}
|
||||
if _, err := posixStorage.StatFile(testCase.srcVol, testCase.srcPath); err != testCase.expectedErr {
|
||||
t.Fatalf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user