2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-06-29 06:13:44 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-06-29 06:13:44 -04:00
|
|
|
|
|
|
|
import (
|
2016-09-13 14:01:10 -04:00
|
|
|
"bytes"
|
2017-01-16 20:05:00 -05:00
|
|
|
"os"
|
2016-06-29 06:13:44 -04:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2019-03-14 16:08:51 -04:00
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2016-06-29 06:13:44 -04:00
|
|
|
)
|
|
|
|
|
2017-09-25 17:47:58 -04:00
|
|
|
// Tests for if parent directory is object
|
|
|
|
func TestFSParentDirIsObject(t *testing.T) {
|
|
|
|
obj, disk, err := prepareFS()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(disk)
|
|
|
|
|
|
|
|
bucketName := "testbucket"
|
|
|
|
objectName := "object"
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if err = obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{}); err != nil {
|
2017-09-25 17:47:58 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
objectContent := "12345"
|
2020-04-09 12:30:02 -04:00
|
|
|
objInfo, err := obj.PutObject(GlobalContext, bucketName, objectName,
|
2019-02-09 00:31:06 -05:00
|
|
|
mustGetPutObjReader(t, bytes.NewReader([]byte(objectContent)), int64(len(objectContent)), "", ""), ObjectOptions{})
|
2017-09-25 17:47:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if objInfo.Name != objectName {
|
|
|
|
t.Fatalf("Unexpected object name returned got %s, expected %s", objInfo.Name, objectName)
|
|
|
|
}
|
|
|
|
|
2018-02-20 15:21:12 -05:00
|
|
|
fs := obj.(*FSObjects)
|
2017-09-25 17:47:58 -04:00
|
|
|
testCases := []struct {
|
|
|
|
parentIsObject bool
|
|
|
|
objectName string
|
|
|
|
}{
|
|
|
|
// parentIsObject is true if object is available.
|
|
|
|
{
|
|
|
|
parentIsObject: true,
|
|
|
|
objectName: objectName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
parentIsObject: false,
|
|
|
|
objectName: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
parentIsObject: false,
|
|
|
|
objectName: ".",
|
|
|
|
},
|
|
|
|
// Should not cause infinite loop.
|
|
|
|
{
|
|
|
|
parentIsObject: false,
|
2019-08-06 15:08:58 -04:00
|
|
|
objectName: SlashSeparator,
|
2017-09-25 17:47:58 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
parentIsObject: false,
|
|
|
|
objectName: "\\",
|
|
|
|
},
|
|
|
|
// Should not cause infinite loop with double forward slash.
|
|
|
|
{
|
|
|
|
parentIsObject: false,
|
|
|
|
objectName: "//",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for i, testCase := range testCases {
|
2020-04-09 12:30:02 -04:00
|
|
|
gotValue := fs.parentDirIsObject(GlobalContext, bucketName, testCase.objectName)
|
2017-09-25 17:47:58 -04:00
|
|
|
if testCase.parentIsObject != gotValue {
|
|
|
|
t.Errorf("Test %d: Unexpected value returned got %t, expected %t", i+1, gotValue, testCase.parentIsObject)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 06:13:44 -04:00
|
|
|
// TestNewFS - tests initialization of all input disks
|
|
|
|
// and constructs a valid `FS` object layer.
|
|
|
|
func TestNewFS(t *testing.T) {
|
|
|
|
// Do not attempt to create this path, the test validates
|
2018-02-20 15:21:12 -05:00
|
|
|
// so that NewFSObjectLayer initializes non existing paths
|
2016-06-29 06:13:44 -04:00
|
|
|
// and successfully returns initialized object layer.
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2016-06-29 06:13:44 -04:00
|
|
|
|
2018-02-20 15:21:12 -05:00
|
|
|
_, err := NewFSObjectLayer("")
|
2016-10-05 15:48:07 -04:00
|
|
|
if err != errInvalidArgument {
|
|
|
|
t.Errorf("Expecting error invalid argument, got %s", err)
|
|
|
|
}
|
2018-02-20 15:21:12 -05:00
|
|
|
_, err = NewFSObjectLayer(disk)
|
2016-10-05 15:48:07 -04:00
|
|
|
if err != nil {
|
|
|
|
errMsg := "Unable to recognize backend format, Disk is not in FS format."
|
|
|
|
if err.Error() == errMsg {
|
|
|
|
t.Errorf("Expecting %s, got %s", errMsg, err)
|
2016-07-03 23:01:40 -04:00
|
|
|
}
|
2016-06-29 06:13:44 -04:00
|
|
|
}
|
|
|
|
}
|
2016-09-13 14:01:10 -04:00
|
|
|
|
2016-11-11 19:36:07 -05:00
|
|
|
// TestFSShutdown - initialize a new FS object layer then calls
|
|
|
|
// Shutdown to check returned results
|
2016-09-13 14:01:10 -04:00
|
|
|
func TestFSShutdown(t *testing.T) {
|
2016-11-11 19:36:07 -05:00
|
|
|
bucketName := "testbucket"
|
|
|
|
objectName := "object"
|
2016-11-09 13:10:14 -05:00
|
|
|
// Create and return an fsObject with its path in the disk
|
2018-02-20 15:21:12 -05:00
|
|
|
prepareTest := func() (*FSObjects, string) {
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2016-11-09 13:10:14 -05:00
|
|
|
obj := initFSObjects(disk, t)
|
2018-02-20 15:21:12 -05:00
|
|
|
fs := obj.(*FSObjects)
|
2018-08-15 00:41:47 -04:00
|
|
|
|
2016-11-09 13:10:14 -05:00
|
|
|
objectContent := "12345"
|
2020-06-12 23:04:01 -04:00
|
|
|
obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{})
|
2020-04-09 12:30:02 -04:00
|
|
|
obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte(objectContent)), int64(len(objectContent)), "", ""), ObjectOptions{})
|
2016-11-09 13:10:14 -05:00
|
|
|
return fs, disk
|
|
|
|
}
|
2016-09-13 14:01:10 -04:00
|
|
|
|
2016-09-16 16:06:49 -04:00
|
|
|
// Test Shutdown with regular conditions
|
2016-11-09 13:10:14 -05:00
|
|
|
fs, disk := prepareTest()
|
2020-04-09 12:30:02 -04:00
|
|
|
if err := fs.Shutdown(GlobalContext); err != nil {
|
2016-09-13 14:01:10 -04:00
|
|
|
t.Fatal("Cannot shutdown the FS object: ", err)
|
|
|
|
}
|
2017-08-12 22:25:43 -04:00
|
|
|
os.RemoveAll(disk)
|
2016-09-13 14:01:10 -04:00
|
|
|
|
2016-11-09 13:10:14 -05:00
|
|
|
// Test Shutdown with faulty disk
|
2017-02-07 15:51:23 -05:00
|
|
|
fs, disk = prepareTest()
|
2020-06-12 23:04:01 -04:00
|
|
|
fs.DeleteObject(GlobalContext, bucketName, objectName, ObjectOptions{})
|
2017-08-12 22:25:43 -04:00
|
|
|
os.RemoveAll(disk)
|
2020-04-09 12:30:02 -04:00
|
|
|
if err := fs.Shutdown(GlobalContext); err != nil {
|
2017-02-07 15:51:23 -05:00
|
|
|
t.Fatal("Got unexpected fs shutdown error: ", err)
|
2016-12-01 16:59:06 -05:00
|
|
|
}
|
2016-09-16 16:06:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestFSGetBucketInfo - test GetBucketInfo with healty and faulty disks
|
|
|
|
func TestFSGetBucketInfo(t *testing.T) {
|
|
|
|
// Prepare for testing
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
obj := initFSObjects(disk, t)
|
2018-02-20 15:21:12 -05:00
|
|
|
fs := obj.(*FSObjects)
|
2016-09-16 16:06:49 -04:00
|
|
|
bucketName := "bucket"
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
err := obj.MakeBucketWithLocation(GlobalContext, "a", BucketOptions{})
|
2018-04-23 23:27:33 -04:00
|
|
|
if !isSameType(err, BucketNameInvalid{}) {
|
|
|
|
t.Fatal("BucketNameInvalid error not returned")
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
err = obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{})
|
2018-04-23 23:27:33 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-09-16 16:06:49 -04:00
|
|
|
|
|
|
|
// Test with valid parameters
|
2020-04-09 12:30:02 -04:00
|
|
|
info, err := fs.GetBucketInfo(GlobalContext, bucketName)
|
2016-09-16 16:06:49 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if info.Name != bucketName {
|
|
|
|
t.Fatalf("wrong bucket name, expected: %s, found: %s", bucketName, info.Name)
|
|
|
|
}
|
|
|
|
|
2018-04-23 23:27:33 -04:00
|
|
|
// Test with non-existent bucket
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = fs.GetBucketInfo(GlobalContext, "a")
|
2018-04-23 23:27:33 -04:00
|
|
|
if !isSameType(err, BucketNotFound{}) {
|
|
|
|
t.Fatal("BucketNotFound error not returned")
|
2016-09-16 16:06:49 -04:00
|
|
|
}
|
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// Check for buckets and should get disk not found.
|
2018-06-04 21:35:41 -04:00
|
|
|
os.RemoveAll(disk)
|
2017-08-10 17:11:57 -04:00
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
if _, err = fs.GetBucketInfo(GlobalContext, bucketName); err != nil {
|
2018-06-04 21:35:41 -04:00
|
|
|
if !isSameType(err, BucketNotFound{}) {
|
|
|
|
t.Fatal("BucketNotFound error not returned")
|
|
|
|
}
|
2016-09-16 16:06:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 20:46:46 -04:00
|
|
|
func TestFSPutObject(t *testing.T) {
|
|
|
|
// Prepare for tests
|
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2017-05-09 20:46:46 -04:00
|
|
|
|
|
|
|
obj := initFSObjects(disk, t)
|
|
|
|
bucketName := "bucket"
|
|
|
|
objectName := "1/2/3/4/object"
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{}); err != nil {
|
2017-05-09 20:46:46 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-05-25 12:22:43 -04:00
|
|
|
|
|
|
|
// With a regular object.
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err := obj.PutObject(GlobalContext, bucketName+"non-existent", objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{})
|
2017-05-25 12:22:43 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Unexpected should fail here, bucket doesn't exist")
|
|
|
|
}
|
2018-04-10 12:36:37 -04:00
|
|
|
if _, ok := err.(BucketNotFound); !ok {
|
2017-05-25 12:22:43 -04:00
|
|
|
t.Fatalf("Expected error type BucketNotFound, got %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// With a directory object.
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucketName+"non-existent", objectName+SlashSeparator, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), 0, "", ""), ObjectOptions{})
|
2017-05-25 12:22:43 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Unexpected should fail here, bucket doesn't exist")
|
|
|
|
}
|
2018-04-10 12:36:37 -04:00
|
|
|
if _, ok := err.(BucketNotFound); !ok {
|
2017-05-25 12:22:43 -04:00
|
|
|
t.Fatalf("Expected error type BucketNotFound, got %#v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{})
|
2017-05-09 20:46:46 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucketName, objectName+"/1", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{})
|
2017-05-09 20:46:46 -04:00
|
|
|
if err == nil {
|
2017-05-25 12:22:43 -04:00
|
|
|
t.Fatal("Unexpected should fail here, backend corruption occurred")
|
2017-05-09 20:46:46 -04:00
|
|
|
}
|
2019-03-20 16:06:53 -04:00
|
|
|
if nerr, ok := err.(ParentIsObject); !ok {
|
|
|
|
t.Fatalf("Expected ParentIsObject, got %#v", err)
|
2017-05-09 20:46:46 -04:00
|
|
|
} else {
|
|
|
|
if nerr.Bucket != "bucket" {
|
|
|
|
t.Fatalf("Expected 'bucket', got %s", nerr.Bucket)
|
|
|
|
}
|
|
|
|
if nerr.Object != "1/2/3/4/object/1" {
|
|
|
|
t.Fatalf("Expected '1/2/3/4/object/1', got %s", nerr.Object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucketName, objectName+"/1/", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), 0, "", ""), ObjectOptions{})
|
2017-05-09 20:46:46 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Unexpected should fail here, backned corruption occurred")
|
|
|
|
}
|
2019-03-20 16:06:53 -04:00
|
|
|
if nerr, ok := err.(ParentIsObject); !ok {
|
|
|
|
t.Fatalf("Expected ParentIsObject, got %#v", err)
|
2017-05-09 20:46:46 -04:00
|
|
|
} else {
|
|
|
|
if nerr.Bucket != "bucket" {
|
|
|
|
t.Fatalf("Expected 'bucket', got %s", nerr.Bucket)
|
|
|
|
}
|
|
|
|
if nerr.Object != "1/2/3/4/object/1/" {
|
|
|
|
t.Fatalf("Expected '1/2/3/4/object/1/', got %s", nerr.Object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 16:06:49 -04:00
|
|
|
// TestFSDeleteObject - test fs.DeleteObject() with healthy and corrupted disks
|
|
|
|
func TestFSDeleteObject(t *testing.T) {
|
|
|
|
// Prepare for tests
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
obj := initFSObjects(disk, t)
|
2018-02-20 15:21:12 -05:00
|
|
|
fs := obj.(*FSObjects)
|
2016-09-16 16:06:49 -04:00
|
|
|
bucketName := "bucket"
|
|
|
|
objectName := "object"
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{})
|
2020-04-09 12:30:02 -04:00
|
|
|
obj.PutObject(GlobalContext, bucketName, objectName, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{})
|
2016-09-16 16:06:49 -04:00
|
|
|
|
|
|
|
// Test with invalid bucket name
|
2020-06-12 23:04:01 -04:00
|
|
|
if _, err := fs.DeleteObject(GlobalContext, "fo", objectName, ObjectOptions{}); !isSameType(err, BucketNameInvalid{}) {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
2017-01-16 20:05:00 -05:00
|
|
|
// Test with bucket does not exist
|
2020-06-12 23:04:01 -04:00
|
|
|
if _, err := fs.DeleteObject(GlobalContext, "foobucket", "fooobject", ObjectOptions{}); !isSameType(err, BucketNotFound{}) {
|
2017-01-16 20:05:00 -05:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
2016-09-16 16:06:49 -04:00
|
|
|
// Test with invalid object name
|
2020-06-12 23:04:01 -04:00
|
|
|
if _, err := fs.DeleteObject(GlobalContext, bucketName, "\\", ObjectOptions{}); !(isSameType(err, ObjectNotFound{}) || isSameType(err, ObjectNameInvalid{})) {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
2017-01-16 20:05:00 -05:00
|
|
|
// Test with object does not exist.
|
2020-06-12 23:04:01 -04:00
|
|
|
if _, err := fs.DeleteObject(GlobalContext, bucketName, "foooobject", ObjectOptions{}); !isSameType(err, ObjectNotFound{}) {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
// Test with valid condition
|
2020-06-12 23:04:01 -04:00
|
|
|
if _, err := fs.DeleteObject(GlobalContext, bucketName, objectName, ObjectOptions{}); err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// Delete object should err disk not found.
|
2018-06-04 21:35:41 -04:00
|
|
|
os.RemoveAll(disk)
|
2020-06-12 23:04:01 -04:00
|
|
|
if _, err := fs.DeleteObject(GlobalContext, bucketName, objectName, ObjectOptions{}); err != nil {
|
2018-04-10 12:36:37 -04:00
|
|
|
if !isSameType(err, BucketNotFound{}) {
|
2017-01-16 20:05:00 -05:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
2016-09-16 16:06:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestFSDeleteBucket - tests for fs DeleteBucket
|
|
|
|
func TestFSDeleteBucket(t *testing.T) {
|
|
|
|
// Prepare for testing
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
obj := initFSObjects(disk, t)
|
2018-02-20 15:21:12 -05:00
|
|
|
fs := obj.(*FSObjects)
|
2016-09-16 16:06:49 -04:00
|
|
|
bucketName := "bucket"
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
err := obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{})
|
2016-09-16 16:06:49 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with an invalid bucket name
|
2020-04-09 12:30:02 -04:00
|
|
|
if err = fs.DeleteBucket(GlobalContext, "fo", false); !isSameType(err, BucketNotFound{}) {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
2018-04-23 23:27:33 -04:00
|
|
|
|
2016-09-16 16:06:49 -04:00
|
|
|
// Test with an inexistant bucket
|
2020-04-09 12:30:02 -04:00
|
|
|
if err = fs.DeleteBucket(GlobalContext, "foobucket", false); !isSameType(err, BucketNotFound{}) {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
// Test with a valid case
|
2020-04-09 12:30:02 -04:00
|
|
|
if err = fs.DeleteBucket(GlobalContext, bucketName, false); err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{})
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2017-08-10 17:11:57 -04:00
|
|
|
// Delete bucket should get error disk not found.
|
2018-06-04 21:35:41 -04:00
|
|
|
os.RemoveAll(disk)
|
2020-04-09 12:30:02 -04:00
|
|
|
if err = fs.DeleteBucket(GlobalContext, bucketName, false); err != nil {
|
2018-04-10 12:36:37 -04:00
|
|
|
if !isSameType(err, BucketNotFound{}) {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestFSListBuckets - tests for fs ListBuckets
|
|
|
|
func TestFSListBuckets(t *testing.T) {
|
|
|
|
// Prepare for tests
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
obj := initFSObjects(disk, t)
|
2018-02-20 15:21:12 -05:00
|
|
|
fs := obj.(*FSObjects)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
|
|
|
bucketName := "bucket"
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{}); err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a bucket with invalid name
|
2017-08-12 22:25:43 -04:00
|
|
|
if err := os.MkdirAll(pathJoin(fs.fsPath, "vo^"), 0777); err != nil {
|
2017-01-16 20:05:00 -05:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
f, err := os.Create(pathJoin(fs.fsPath, "test"))
|
|
|
|
if err != nil {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
2017-01-16 20:05:00 -05:00
|
|
|
f.Close()
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// Test list buckets to have only one entry.
|
2020-04-09 12:30:02 -04:00
|
|
|
buckets, err := fs.ListBuckets(GlobalContext)
|
2016-09-16 16:06:49 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
if len(buckets) != 1 {
|
2017-01-16 20:05:00 -05:00
|
|
|
t.Fatal("ListBuckets not working properly", buckets)
|
2016-09-16 16:06:49 -04:00
|
|
|
}
|
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// Test ListBuckets with disk not found.
|
2018-06-04 21:35:41 -04:00
|
|
|
os.RemoveAll(disk)
|
2020-04-09 12:30:02 -04:00
|
|
|
if _, err := fs.ListBuckets(GlobalContext); err != nil {
|
2018-04-10 12:36:37 -04:00
|
|
|
if err != errDiskNotFound {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatal("Unexpected error: ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestFSHealObject - tests for fs HealObject
|
|
|
|
func TestFSHealObject(t *testing.T) {
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
obj := initFSObjects(disk, t)
|
2020-06-12 23:04:01 -04:00
|
|
|
_, err := obj.HealObject(GlobalContext, "bucket", "object", "", madmin.HealOpts{})
|
2018-04-10 12:36:37 -04:00
|
|
|
if err == nil || !isSameType(err, NotImplemented{}) {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatalf("Heal Object should return NotImplemented error ")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 20:35:09 -04:00
|
|
|
// TestFSHealObjects - tests for fs HealObjects to return not implemented.
|
|
|
|
func TestFSHealObjects(t *testing.T) {
|
2016-12-16 01:25:05 -05:00
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2016-09-16 16:06:49 -04:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
obj := initFSObjects(disk, t)
|
2020-04-09 12:30:02 -04:00
|
|
|
err := obj.HealObjects(GlobalContext, "bucket", "prefix", madmin.HealOpts{}, nil)
|
2018-04-10 12:36:37 -04:00
|
|
|
if err == nil || !isSameType(err, NotImplemented{}) {
|
2016-09-16 16:06:49 -04:00
|
|
|
t.Fatalf("Heal Object should return NotImplemented error ")
|
|
|
|
}
|
2016-09-13 14:01:10 -04:00
|
|
|
}
|