mirror of
https://github.com/pgsty/minio.git
synced 2026-08-10 08:13:28 +03:00
tests: Added GetObject, DeleteObject and PutObject unit-tests (#2222)
This commit is contained in:
committed by
Harshavardhana
parent
0eaf684777
commit
5730d40478
@@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -60,3 +61,186 @@ func TestRepeatPutObjectPart(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestXLDeleteObjectBasic(t *testing.T) {
|
||||
testCases := []struct {
|
||||
bucket string
|
||||
object string
|
||||
expectedErr error
|
||||
}{
|
||||
{".test", "obj", BucketNameInvalid{Bucket: ".test"}},
|
||||
{"----", "obj", BucketNameInvalid{Bucket: "----"}},
|
||||
{"bucket", "", ObjectNameInvalid{Bucket: "bucket", Object: ""}},
|
||||
{"bucket", "obj/", ObjectNameInvalid{Bucket: "bucket", Object: "obj/"}},
|
||||
{"bucket", "/obj", ObjectNameInvalid{Bucket: "bucket", Object: "/obj"}},
|
||||
{"bucket", "doesnotexist", ObjectNotFound{Bucket: "bucket", Object: "doesnotexist"}},
|
||||
{"bucket", "obj", nil},
|
||||
}
|
||||
|
||||
// Create an instance of xl backend
|
||||
xl, fsDirs, err := getXLObjectLayer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Make bucket for Test 7 to pass
|
||||
err = xl.MakeBucket("bucket")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Create object "obj" under bucket "bucket" for Test 7 to pass
|
||||
_, err = xl.PutObject("bucket", "obj", int64(len("abcd")), bytes.NewReader([]byte("abcd")), nil)
|
||||
|
||||
for i, test := range testCases {
|
||||
actualErr := xl.DeleteObject(test.bucket, test.object)
|
||||
if test.expectedErr != nil && actualErr != test.expectedErr {
|
||||
t.Errorf("Test %d: Expected to fail with %s, but failed with %s", i+1, test.expectedErr, actualErr)
|
||||
}
|
||||
if test.expectedErr == nil && actualErr != nil {
|
||||
t.Errorf("Test %d: Expected to pass, but failed with %s", i+1, actualErr)
|
||||
}
|
||||
}
|
||||
// Cleanup backend directories
|
||||
removeRoots(fsDirs)
|
||||
}
|
||||
|
||||
func TestXLDeleteObjectDiskNotFound(t *testing.T) {
|
||||
// Create an instance of xl backend.
|
||||
obj, fsDirs, err := getXLObjectLayer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
xl := obj.(xlObjects)
|
||||
|
||||
// Create "bucket"
|
||||
err = obj.MakeBucket("bucket")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bucket := "bucket"
|
||||
object := "object"
|
||||
// Create object "obj" under bucket "bucket".
|
||||
_, err = obj.PutObject(bucket, object, int64(len("abcd")), bytes.NewReader([]byte("abcd")), nil)
|
||||
|
||||
// for a 16 disk setup, quorum is 9. To simulate disks not found yet
|
||||
// quorum is available, we remove disks leaving quorum disks behind.
|
||||
for i := range xl.storageDisks[:7] {
|
||||
xl.storageDisks[i] = newFaultyDisk(xl.storageDisks[i].(*posix), 0)
|
||||
}
|
||||
err = obj.DeleteObject(bucket, object)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Create "obj" under "bucket".
|
||||
_, err = obj.PutObject(bucket, object, int64(len("abcd")), bytes.NewReader([]byte("abcd")), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Remove one more disk to 'lose' quorum, by setting it to nil.
|
||||
xl.storageDisks[7] = &faultyDisk{}
|
||||
xl.storageDisks[8] = &faultyDisk{}
|
||||
err = obj.DeleteObject(bucket, object)
|
||||
if err != toObjectErr(errXLWriteQuorum, bucket, object) {
|
||||
t.Errorf("Expected deleteObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err)
|
||||
}
|
||||
// Cleanup backend directories
|
||||
removeRoots(fsDirs)
|
||||
}
|
||||
|
||||
func TestGetObjectNoQuorum(t *testing.T) {
|
||||
// Create an instance of xl backend.
|
||||
obj, fsDirs, err := getXLObjectLayer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
xl := obj.(xlObjects)
|
||||
|
||||
// Create "bucket"
|
||||
err = obj.MakeBucket("bucket")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bucket := "bucket"
|
||||
object := "object"
|
||||
// Create "object" under "bucket".
|
||||
_, err = obj.PutObject(bucket, object, int64(len("abcd")), bytes.NewReader([]byte("abcd")), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Disable caching to avoid returning early and not covering other code-paths
|
||||
xl.objCacheEnabled = false
|
||||
// Make 9 disks offline, which leaves less than quorum number of disks
|
||||
// in a 16 disk XL setup. The original disks are 'replaced' with
|
||||
// faultyDisks that fail after 'f' successful StorageAPI method
|
||||
// invocations, where f - [0,2)
|
||||
for f := 0; f < 2; f++ {
|
||||
for i := range xl.storageDisks[:9] {
|
||||
switch diskType := xl.storageDisks[i].(type) {
|
||||
case *posix:
|
||||
xl.storageDisks[i] = newFaultyDisk(diskType, f)
|
||||
case *faultyDisk:
|
||||
xl.storageDisks[i] = newFaultyDisk(diskType.disk, f)
|
||||
}
|
||||
}
|
||||
// Fetch object from store.
|
||||
err = xl.GetObject(bucket, object, 0, int64(len("abcd")), ioutil.Discard)
|
||||
if err != toObjectErr(errXLReadQuorum, bucket, object) {
|
||||
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err)
|
||||
}
|
||||
}
|
||||
// Cleanup backend directories.
|
||||
removeRoots(fsDirs)
|
||||
}
|
||||
|
||||
func TestPutObjectNoQuorum(t *testing.T) {
|
||||
// Create an instance of xl backend.
|
||||
obj, fsDirs, err := getXLObjectLayer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
xl := obj.(xlObjects)
|
||||
|
||||
// Create "bucket"
|
||||
err = obj.MakeBucket("bucket")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bucket := "bucket"
|
||||
object := "object"
|
||||
// Create "object" under "bucket".
|
||||
_, err = obj.PutObject(bucket, object, int64(len("abcd")), bytes.NewReader([]byte("abcd")), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Make 9 disks offline, which leaves less than quorum number of disks
|
||||
// in a 16 disk XL setup. The original disks are 'replaced' with
|
||||
// faultyDisks that fail after 'f' successful StorageAPI method
|
||||
// invocations, where f - [0,3)
|
||||
for f := 0; f < 3; f++ {
|
||||
for i := range xl.storageDisks[:9] {
|
||||
switch diskType := xl.storageDisks[i].(type) {
|
||||
case *posix:
|
||||
xl.storageDisks[i] = newFaultyDisk(diskType, f)
|
||||
case *faultyDisk:
|
||||
xl.storageDisks[i] = newFaultyDisk(diskType.disk, f)
|
||||
}
|
||||
}
|
||||
// Upload new content to same object "object"
|
||||
_, err = obj.PutObject(bucket, object, int64(len("abcd")), bytes.NewReader([]byte("abcd")), nil)
|
||||
if err != toObjectErr(errXLWriteQuorum, bucket, object) {
|
||||
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err)
|
||||
}
|
||||
}
|
||||
// Cleanup backend directories.
|
||||
removeRoots(fsDirs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user