@ -1,5 +1,5 @@
/ *
/ *
* Minio Cloud Storage , ( C ) 2015 , 2016 Minio , Inc .
* Minio Cloud Storage , ( C ) 2015 , 2016 , 2017 Minio , Inc .
*
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -21,10 +21,9 @@ import (
"io"
"io"
"math/rand"
"math/rand"
"strconv"
"strconv"
"testing"
humanize "github.com/dustin/go-humanize"
humanize "github.com/dustin/go-humanize"
. "gopkg.in/check.v1"
)
)
// Return pointer to testOneByteReadEOF{}
// Return pointer to testOneByteReadEOF{}
@ -70,35 +69,33 @@ func (r *testOneByteReadNoEOF) Read(p []byte) (n int, err error) {
type ObjectLayerAPISuite struct { }
type ObjectLayerAPISuite struct { }
var _ = Suite ( & ObjectLayerAPISuite { } )
// Wrapper for calling testMakeBucket for both XL and FS.
// Wrapper for calling testMakeBucket for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestMakeBucket ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestMakeBucket ( t * testing . T ) {
ExecObjectLayerTest ( c , testMakeBucket )
ExecObjectLayerTest ( t , testMakeBucket )
}
}
// Tests validate bucket creation.
// Tests validate bucket creation.
func testMakeBucket ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testMakeBucket ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
err := obj . MakeBucketWithLocation ( "bucket-unknown" , "" )
err := obj . MakeBucketWithLocation ( "bucket-unknown" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
}
}
// Wrapper for calling testMultipartObjectCreation for both XL and FS.
// Wrapper for calling testMultipartObjectCreation for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestMultipartObjectCreation ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestMultipartObjectCreation ( t * testing . T ) {
ExecObjectLayerTest ( c , testMultipartObjectCreation )
ExecObjectLayerTest ( t , testMultipartObjectCreation )
}
}
// Tests validate creation of part files during Multipart operation.
// Tests validate creation of part files during Multipart operation.
func testMultipartObjectCreation ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testMultipartObjectCreation ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
err := obj . MakeBucketWithLocation ( "bucket" , "" )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
uploadID , err := obj . NewMultipartUpload ( "bucket" , "key" , nil )
uploadID , err := obj . NewMultipartUpload ( "bucket" , "key" , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
// Create a byte array of 5MiB.
// Create a byte array of 5MiB.
data := bytes . Repeat ( [ ] byte ( "0123456789abcdef" ) , 5 * humanize . MiByte / 16 )
data := bytes . Repeat ( [ ] byte ( "0123456789abcdef" ) , 5 * humanize . MiByte / 16 )
@ -109,10 +106,10 @@ func testMultipartObjectCreation(obj ObjectLayer, instanceType string, c TestErr
var calcPartInfo PartInfo
var calcPartInfo PartInfo
calcPartInfo , err = obj . PutObjectPart ( "bucket" , "key" , uploadID , i , NewHashReader ( bytes . NewBuffer ( data ) , int64 ( len ( data ) ) , expectedETaghex , "" ) )
calcPartInfo , err = obj . PutObjectPart ( "bucket" , "key" , uploadID , i , NewHashReader ( bytes . NewBuffer ( data ) , int64 ( len ( data ) ) , expectedETaghex , "" ) )
if err != nil {
if err != nil {
c . Errorf ( "%s: <ERROR> %s" , instanceType , err )
t . Errorf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if calcPartInfo . ETag != expectedETaghex {
if calcPartInfo . ETag != expectedETaghex {
c . Errorf ( "MD5 Mismatch" )
t . Errorf ( "MD5 Mismatch" )
}
}
completedParts . Parts = append ( completedParts . Parts , completePart {
completedParts . Parts = append ( completedParts . Parts , completePart {
PartNumber : i ,
PartNumber : i ,
@ -121,27 +118,27 @@ func testMultipartObjectCreation(obj ObjectLayer, instanceType string, c TestErr
}
}
objInfo , err := obj . CompleteMultipartUpload ( "bucket" , "key" , uploadID , completedParts . Parts )
objInfo , err := obj . CompleteMultipartUpload ( "bucket" , "key" , uploadID , completedParts . Parts )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if objInfo . ETag != "7d364cb728ce42a74a96d22949beefb2-10" {
if objInfo . ETag != "7d364cb728ce42a74a96d22949beefb2-10" {
c . Errorf ( "Md5 mismtch" )
t . Errorf ( "Md5 mismtch" )
}
}
}
}
// Wrapper for calling testMultipartObjectAbort for both XL and FS.
// Wrapper for calling testMultipartObjectAbort for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestMultipartObjectAbort ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestMultipartObjectAbort ( t * testing . T ) {
ExecObjectLayerTest ( c , testMultipartObjectAbort )
ExecObjectLayerTest ( t , testMultipartObjectAbort )
}
}
// Tests validate abortion of Multipart operation.
// Tests validate abortion of Multipart operation.
func testMultipartObjectAbort ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testMultipartObjectAbort ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
err := obj . MakeBucketWithLocation ( "bucket" , "" )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
uploadID , err := obj . NewMultipartUpload ( "bucket" , "key" , nil )
uploadID , err := obj . NewMultipartUpload ( "bucket" , "key" , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
parts := make ( map [ int ] string )
parts := make ( map [ int ] string )
@ -159,30 +156,30 @@ func testMultipartObjectAbort(obj ObjectLayer, instanceType string, c TestErrHan
var calcPartInfo PartInfo
var calcPartInfo PartInfo
calcPartInfo , err = obj . PutObjectPart ( "bucket" , "key" , uploadID , i , NewHashReader ( bytes . NewBufferString ( randomString ) , int64 ( len ( randomString ) ) , expectedETaghex , "" ) )
calcPartInfo , err = obj . PutObjectPart ( "bucket" , "key" , uploadID , i , NewHashReader ( bytes . NewBufferString ( randomString ) , int64 ( len ( randomString ) ) , expectedETaghex , "" ) )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if calcPartInfo . ETag != expectedETaghex {
if calcPartInfo . ETag != expectedETaghex {
c . Errorf ( "Md5 Mismatch" )
t . Errorf ( "Md5 Mismatch" )
}
}
parts [ i ] = expectedETaghex
parts [ i ] = expectedETaghex
}
}
err = obj . AbortMultipartUpload ( "bucket" , "key" , uploadID )
err = obj . AbortMultipartUpload ( "bucket" , "key" , uploadID )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
}
}
// Wrapper for calling testMultipleObjectCreation for both XL and FS.
// Wrapper for calling testMultipleObjectCreation for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestMultipleObjectCreation ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestMultipleObjectCreation ( t * testing . T ) {
ExecObjectLayerTest ( c , testMultipleObjectCreation )
ExecObjectLayerTest ( t , testMultipleObjectCreation )
}
}
// Tests validate object creation.
// Tests validate object creation.
func testMultipleObjectCreation ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testMultipleObjectCreation ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
objects := make ( map [ string ] [ ] byte )
objects := make ( map [ string ] [ ] byte )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
for i := 0 ; i < 10 ; i ++ {
for i := 0 ; i < 10 ; i ++ {
randomPerm := rand . Perm ( 100 )
randomPerm := rand . Perm ( 100 )
@ -200,10 +197,10 @@ func testMultipleObjectCreation(obj ObjectLayer, instanceType string, c TestErrH
var objInfo ObjectInfo
var objInfo ObjectInfo
objInfo , err = obj . PutObject ( "bucket" , key , NewHashReader ( bytes . NewBufferString ( randomString ) , int64 ( len ( randomString ) ) , metadata [ "etag" ] , "" ) , metadata )
objInfo , err = obj . PutObject ( "bucket" , key , NewHashReader ( bytes . NewBufferString ( randomString ) , int64 ( len ( randomString ) ) , metadata [ "etag" ] , "" ) , metadata )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if objInfo . ETag != expectedETaghex {
if objInfo . ETag != expectedETaghex {
c . Errorf ( "Md5 Mismatch" )
t . Errorf ( "Md5 Mismatch" )
}
}
}
}
@ -211,40 +208,40 @@ func testMultipleObjectCreation(obj ObjectLayer, instanceType string, c TestErrH
var byteBuffer bytes . Buffer
var byteBuffer bytes . Buffer
err = obj . GetObject ( "bucket" , key , 0 , int64 ( len ( value ) ) , & byteBuffer )
err = obj . GetObject ( "bucket" , key , 0 , int64 ( len ( value ) ) , & byteBuffer )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if ! bytes . Equal ( byteBuffer . Bytes ( ) , value ) {
if ! bytes . Equal ( byteBuffer . Bytes ( ) , value ) {
c . Errorf ( "%s: Mismatch of GetObject data with the expected one." , instanceType )
t . Errorf ( "%s: Mismatch of GetObject data with the expected one." , instanceType )
}
}
objInfo , err := obj . GetObjectInfo ( "bucket" , key )
objInfo , err := obj . GetObjectInfo ( "bucket" , key )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if objInfo . Size != int64 ( len ( value ) ) {
if objInfo . Size != int64 ( len ( value ) ) {
c . Errorf ( "%s: Size mismatch of the GetObject data." , instanceType )
t . Errorf ( "%s: Size mismatch of the GetObject data." , instanceType )
}
}
}
}
}
}
// Wrapper for calling TestPaging for both XL and FS.
// Wrapper for calling TestPaging for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestPaging ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestPaging ( t * testing . T ) {
ExecObjectLayerTest ( c , testPaging )
ExecObjectLayerTest ( t , testPaging )
}
}
// Tests validate creation of objects and the order of listing using various filters for ListObjects operation.
// Tests validate creation of objects and the order of listing using various filters for ListObjects operation.
func testPaging ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testPaging ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
obj . MakeBucketWithLocation ( "bucket" , "" )
obj . MakeBucketWithLocation ( "bucket" , "" )
result , err := obj . ListObjects ( "bucket" , "" , "" , "" , 0 )
result , err := obj . ListObjects ( "bucket" , "" , "" , "" , 0 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( result . Objects ) != 0 {
if len ( result . Objects ) != 0 {
c . Errorf ( "%s: Number of objects in the result different from expected value." , instanceType )
t . Errorf ( "%s: Number of objects in the result different from expected value." , instanceType )
}
}
if result . IsTruncated {
if result . IsTruncated {
c . Errorf ( "%s: Expected IsTruncated to be `false`, but instead found it to be `%v`" , instanceType , result . IsTruncated )
t . Errorf ( "%s: Expected IsTruncated to be `false`, but instead found it to be `%v`" , instanceType , result . IsTruncated )
}
}
uploadContent := "The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed."
uploadContent := "The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed."
@ -253,18 +250,18 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
key := "obj" + strconv . Itoa ( i )
key := "obj" + strconv . Itoa ( i )
_ , err = obj . PutObject ( "bucket" , key , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , key , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
result , err = obj . ListObjects ( "bucket" , "" , "" , "" , 5 )
result , err = obj . ListObjects ( "bucket" , "" , "" , "" , 5 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( result . Objects ) != i + 1 {
if len ( result . Objects ) != i + 1 {
c . Errorf ( "%s: Expected length of objects to be %d, instead found to be %d" , instanceType , len ( result . Objects ) , i + 1 )
t . Errorf ( "%s: Expected length of objects to be %d, instead found to be %d" , instanceType , len ( result . Objects ) , i + 1 )
}
}
if result . IsTruncated {
if result . IsTruncated {
c . Errorf ( "%s: Expected IsTruncated to be `false`, but instead found it to be `%v`" , instanceType , result . IsTruncated )
t . Errorf ( "%s: Expected IsTruncated to be `false`, but instead found it to be `%v`" , instanceType , result . IsTruncated )
}
}
}
}
@ -273,35 +270,35 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
key := "obj" + strconv . Itoa ( i )
key := "obj" + strconv . Itoa ( i )
_ , err = obj . PutObject ( "bucket" , key , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , key , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
result , err = obj . ListObjects ( "bucket" , "obj" , "" , "" , 5 )
result , err = obj . ListObjects ( "bucket" , "obj" , "" , "" , 5 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( result . Objects ) != 5 {
if len ( result . Objects ) != 5 {
c . Errorf ( "%s: Expected length of objects to be %d, instead found to be %d" , instanceType , 5 , len ( result . Objects ) )
t . Errorf ( "%s: Expected length of objects to be %d, instead found to be %d" , instanceType , 5 , len ( result . Objects ) )
}
}
if ! result . IsTruncated {
if ! result . IsTruncated {
c . Errorf ( "%s: Expected IsTruncated to be `true`, but instead found it to be `%v`" , instanceType , result . IsTruncated )
t . Errorf ( "%s: Expected IsTruncated to be `true`, but instead found it to be `%v`" , instanceType , result . IsTruncated )
}
}
}
}
// check paging with prefix at end returns less objects.
// check paging with prefix at end returns less objects.
{
{
_ , err = obj . PutObject ( "bucket" , "newPrefix" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "newPrefix" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
_ , err = obj . PutObject ( "bucket" , "newPrefix2" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "newPrefix2" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
result , err = obj . ListObjects ( "bucket" , "new" , "" , "" , 5 )
result , err = obj . ListObjects ( "bucket" , "new" , "" , "" , 5 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( result . Objects ) != 2 {
if len ( result . Objects ) != 2 {
c . Errorf ( "%s: Expected length of objects to be %d, instead found to be %d" , instanceType , 2 , len ( result . Objects ) )
t . Errorf ( "%s: Expected length of objects to be %d, instead found to be %d" , instanceType , 2 , len ( result . Objects ) )
}
}
}
}
@ -309,22 +306,22 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
{
{
result , err = obj . ListObjects ( "bucket" , "" , "" , "" , 1000 )
result , err = obj . ListObjects ( "bucket" , "" , "" , "" , 1000 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if result . Objects [ 0 ] . Name != "newPrefix" {
if result . Objects [ 0 ] . Name != "newPrefix" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 0 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 0 ] . Name )
}
}
if result . Objects [ 1 ] . Name != "newPrefix2" {
if result . Objects [ 1 ] . Name != "newPrefix2" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 1 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 1 ] . Name )
}
}
if result . Objects [ 2 ] . Name != "obj0" {
if result . Objects [ 2 ] . Name != "obj0" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 2 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 2 ] . Name )
}
}
if result . Objects [ 3 ] . Name != "obj1" {
if result . Objects [ 3 ] . Name != "obj1" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 3 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 3 ] . Name )
}
}
if result . Objects [ 4 ] . Name != "obj10" {
if result . Objects [ 4 ] . Name != "obj10" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 4 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 4 ] . Name )
}
}
}
}
@ -332,21 +329,21 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
{
{
_ , err = obj . PutObject ( "bucket" , "this/is/delimited" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "this/is/delimited" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
_ , err = obj . PutObject ( "bucket" , "this/is/also/a/delimited/file" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "this/is/also/a/delimited/file" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
result , err = obj . ListObjects ( "bucket" , "this/is/" , "" , "/" , 10 )
result , err = obj . ListObjects ( "bucket" , "this/is/" , "" , "/" , 10 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( result . Objects ) != 1 {
if len ( result . Objects ) != 1 {
c . Errorf ( "%s: Expected the number of objects in the result to be %d, but instead found %d" , instanceType , 1 , len ( result . Objects ) )
t . Errorf ( "%s: Expected the number of objects in the result to be %d, but instead found %d" , instanceType , 1 , len ( result . Objects ) )
}
}
if result . Prefixes [ 0 ] != "this/is/also/" {
if result . Prefixes [ 0 ] != "this/is/also/" {
c . Errorf ( "%s: Expected prefix to be `%s`, but instead found `%s`" , instanceType , "this/is/also/" , result . Prefixes [ 0 ] )
t . Errorf ( "%s: Expected prefix to be `%s`, but instead found `%s`" , instanceType , "this/is/also/" , result . Prefixes [ 0 ] )
}
}
}
}
@ -354,26 +351,26 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
{
{
result , err = obj . ListObjects ( "bucket" , "" , "" , "/" , 1000 )
result , err = obj . ListObjects ( "bucket" , "" , "" , "/" , 1000 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if result . Objects [ 0 ] . Name != "newPrefix" {
if result . Objects [ 0 ] . Name != "newPrefix" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 0 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 0 ] . Name )
}
}
if result . Objects [ 1 ] . Name != "newPrefix2" {
if result . Objects [ 1 ] . Name != "newPrefix2" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 1 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 1 ] . Name )
}
}
if result . Objects [ 2 ] . Name != "obj0" {
if result . Objects [ 2 ] . Name != "obj0" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 2 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 2 ] . Name )
}
}
if result . Objects [ 3 ] . Name != "obj1" {
if result . Objects [ 3 ] . Name != "obj1" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 3 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 3 ] . Name )
}
}
if result . Objects [ 4 ] . Name != "obj10" {
if result . Objects [ 4 ] . Name != "obj10" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 4 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 4 ] . Name )
}
}
if result . Prefixes [ 0 ] != "this/" {
if result . Prefixes [ 0 ] != "this/" {
c . Errorf ( "%s: Expected the prefix to be `%s`, but instead found `%s`" , instanceType , "this/" , result . Prefixes [ 0 ] )
t . Errorf ( "%s: Expected the prefix to be `%s`, but instead found `%s`" , instanceType , "this/" , result . Prefixes [ 0 ] )
}
}
}
}
@ -382,181 +379,181 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
result , err = obj . ListObjects ( "bucket" , "" , "newPrefix" , "" , 3 )
result , err = obj . ListObjects ( "bucket" , "" , "newPrefix" , "" , 3 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if result . Objects [ 0 ] . Name != "newPrefix2" {
if result . Objects [ 0 ] . Name != "newPrefix2" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix2" , result . Objects [ 0 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix2" , result . Objects [ 0 ] . Name )
}
}
if result . Objects [ 1 ] . Name != "obj0" {
if result . Objects [ 1 ] . Name != "obj0" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj0" , result . Objects [ 1 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj0" , result . Objects [ 1 ] . Name )
}
}
if result . Objects [ 2 ] . Name != "obj1" {
if result . Objects [ 2 ] . Name != "obj1" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj1" , result . Objects [ 2 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj1" , result . Objects [ 2 ] . Name )
}
}
}
}
// check ordering of results with prefix.
// check ordering of results with prefix.
{
{
result , err = obj . ListObjects ( "bucket" , "obj" , "" , "" , 1000 )
result , err = obj . ListObjects ( "bucket" , "obj" , "" , "" , 1000 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if result . Objects [ 0 ] . Name != "obj0" {
if result . Objects [ 0 ] . Name != "obj0" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj0" , result . Objects [ 0 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj0" , result . Objects [ 0 ] . Name )
}
}
if result . Objects [ 1 ] . Name != "obj1" {
if result . Objects [ 1 ] . Name != "obj1" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj1" , result . Objects [ 1 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj1" , result . Objects [ 1 ] . Name )
}
}
if result . Objects [ 2 ] . Name != "obj10" {
if result . Objects [ 2 ] . Name != "obj10" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj10" , result . Objects [ 2 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj10" , result . Objects [ 2 ] . Name )
}
}
if result . Objects [ 3 ] . Name != "obj2" {
if result . Objects [ 3 ] . Name != "obj2" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj2" , result . Objects [ 3 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj2" , result . Objects [ 3 ] . Name )
}
}
if result . Objects [ 4 ] . Name != "obj3" {
if result . Objects [ 4 ] . Name != "obj3" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj3" , result . Objects [ 4 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "obj3" , result . Objects [ 4 ] . Name )
}
}
}
}
// check ordering of results with prefix and no paging.
// check ordering of results with prefix and no paging.
{
{
result , err = obj . ListObjects ( "bucket" , "new" , "" , "" , 5 )
result , err = obj . ListObjects ( "bucket" , "new" , "" , "" , 5 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if result . Objects [ 0 ] . Name != "newPrefix" {
if result . Objects [ 0 ] . Name != "newPrefix" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 0 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix" , result . Objects [ 0 ] . Name )
}
}
if result . Objects [ 1 ] . Name != "newPrefix2" {
if result . Objects [ 1 ] . Name != "newPrefix2" {
c . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix2" , result . Objects [ 0 ] . Name )
t . Errorf ( "%s: Expected the object name to be `%s`, but instead found `%s`" , instanceType , "newPrefix2" , result . Objects [ 0 ] . Name )
}
}
}
}
}
}
// Wrapper for calling testObjectOverwriteWorks for both XL and FS.
// Wrapper for calling testObjectOverwriteWorks for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestObjectOverwriteWorks ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestObjectOverwriteWorks ( t * testing . T ) {
ExecObjectLayerTest ( c , testObjectOverwriteWorks )
ExecObjectLayerTest ( t , testObjectOverwriteWorks )
}
}
// Tests validate overwriting of an existing object.
// Tests validate overwriting of an existing object.
func testObjectOverwriteWorks ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testObjectOverwriteWorks ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
err := obj . MakeBucketWithLocation ( "bucket" , "" )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
uploadContent := "The list of parts was not in ascending order. The parts list must be specified in order by part number."
uploadContent := "The list of parts was not in ascending order. The parts list must be specified in order by part number."
length := int64 ( len ( uploadContent ) )
length := int64 ( len ( uploadContent ) )
_ , err = obj . PutObject ( "bucket" , "object" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , length , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "object" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , length , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
uploadContent = "The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed."
uploadContent = "The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed."
length = int64 ( len ( uploadContent ) )
length = int64 ( len ( uploadContent ) )
_ , err = obj . PutObject ( "bucket" , "object" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , length , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "object" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , length , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
var bytesBuffer bytes . Buffer
var bytesBuffer bytes . Buffer
err = obj . GetObject ( "bucket" , "object" , 0 , length , & bytesBuffer )
err = obj . GetObject ( "bucket" , "object" , 0 , length , & bytesBuffer )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if string ( bytesBuffer . Bytes ( ) ) != "The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed." {
if string ( bytesBuffer . Bytes ( ) ) != "The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed." {
c . Errorf ( "%s: Invalid upload ID error mismatch." , instanceType )
t . Errorf ( "%s: Invalid upload ID error mismatch." , instanceType )
}
}
}
}
// Wrapper for calling testNonExistantBucketOperations for both XL and FS.
// Wrapper for calling testNonExistantBucketOperations for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestNonExistantBucketOperations ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestNonExistantBucketOperations ( t * testing . T ) {
ExecObjectLayerTest ( c , testNonExistantBucketOperations )
ExecObjectLayerTest ( t , testNonExistantBucketOperations )
}
}
// Tests validate that bucket operation on non-existent bucket fails.
// Tests validate that bucket operation on non-existent bucket fails.
func testNonExistantBucketOperations ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testNonExistantBucketOperations ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
_ , err := obj . PutObject ( "bucket1" , "object" , NewHashReader ( bytes . NewBufferString ( "one" ) , int64 ( len ( "one" ) ) , "" , "" ) , nil )
_ , err := obj . PutObject ( "bucket1" , "object" , NewHashReader ( bytes . NewBufferString ( "one" ) , int64 ( len ( "one" ) ) , "" , "" ) , nil )
if err == nil {
if err == nil {
c . Fatal ( "Expected error but found nil" )
t . Fatal ( "Expected error but found nil" )
}
}
if err . Error ( ) != "Bucket not found: bucket1" {
if err . Error ( ) != "Bucket not found: bucket1" {
c . Errorf ( "%s: Expected the error msg to be `%s`, but instead found `%s`" , instanceType , "Bucket not found: bucket1" , err . Error ( ) )
t . Errorf ( "%s: Expected the error msg to be `%s`, but instead found `%s`" , instanceType , "Bucket not found: bucket1" , err . Error ( ) )
}
}
}
}
// Wrapper for calling testBucketRecreateFails for both XL and FS.
// Wrapper for calling testBucketRecreateFails for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestBucketRecreateFails ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestBucketRecreateFails ( t * testing . T ) {
ExecObjectLayerTest ( c , testBucketRecreateFails )
ExecObjectLayerTest ( t , testBucketRecreateFails )
}
}
// Tests validate that recreation of the bucket fails.
// Tests validate that recreation of the bucket fails.
func testBucketRecreateFails ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testBucketRecreateFails ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
err := obj . MakeBucketWithLocation ( "string" , "" )
err := obj . MakeBucketWithLocation ( "string" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
err = obj . MakeBucketWithLocation ( "string" , "" )
err = obj . MakeBucketWithLocation ( "string" , "" )
if err == nil {
if err == nil {
c . Fatalf ( "%s: Expected error but found nil." , instanceType )
t . Fatalf ( "%s: Expected error but found nil." , instanceType )
}
}
if err . Error ( ) != "Bucket exists: string" {
if err . Error ( ) != "Bucket exists: string" {
c . Errorf ( "%s: Expected the error message to be `%s`, but instead found `%s`" , instanceType , "Bucket exists: string" , err . Error ( ) )
t . Errorf ( "%s: Expected the error message to be `%s`, but instead found `%s`" , instanceType , "Bucket exists: string" , err . Error ( ) )
}
}
}
}
// Wrapper for calling testPutObject for both XL and FS.
// Wrapper for calling testPutObject for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestPutObject ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestPutObject ( t * testing . T ) {
ExecObjectLayerTest ( c , testPutObject )
ExecObjectLayerTest ( t , testPutObject )
}
}
// Tests validate PutObject without prefix.
// Tests validate PutObject without prefix.
func testPutObject ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testPutObject ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
content := [ ] byte ( "testcontent" )
content := [ ] byte ( "testcontent" )
length := int64 ( len ( content ) )
length := int64 ( len ( content ) )
readerEOF := newTestReaderEOF ( content )
readerEOF := newTestReaderEOF ( content )
readerNoEOF := newTestReaderNoEOF ( content )
readerNoEOF := newTestReaderNoEOF ( content )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
var bytesBuffer1 bytes . Buffer
var bytesBuffer1 bytes . Buffer
_ , err = obj . PutObject ( "bucket" , "object" , NewHashReader ( readerEOF , length , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "object" , NewHashReader ( readerEOF , length , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
err = obj . GetObject ( "bucket" , "object" , 0 , length , & bytesBuffer1 )
err = obj . GetObject ( "bucket" , "object" , 0 , length , & bytesBuffer1 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( bytesBuffer1 . Bytes ( ) ) != len ( content ) {
if len ( bytesBuffer1 . Bytes ( ) ) != len ( content ) {
c . Errorf ( "%s: Expected content length to be `%d`, but instead found `%d`" , instanceType , len ( content ) , len ( bytesBuffer1 . Bytes ( ) ) )
t . Errorf ( "%s: Expected content length to be `%d`, but instead found `%d`" , instanceType , len ( content ) , len ( bytesBuffer1 . Bytes ( ) ) )
}
}
var bytesBuffer2 bytes . Buffer
var bytesBuffer2 bytes . Buffer
_ , err = obj . PutObject ( "bucket" , "object" , NewHashReader ( readerNoEOF , length , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "object" , NewHashReader ( readerNoEOF , length , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
err = obj . GetObject ( "bucket" , "object" , 0 , length , & bytesBuffer2 )
err = obj . GetObject ( "bucket" , "object" , 0 , length , & bytesBuffer2 )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( bytesBuffer2 . Bytes ( ) ) != len ( content ) {
if len ( bytesBuffer2 . Bytes ( ) ) != len ( content ) {
c . Errorf ( "%s: Expected content length to be `%d`, but instead found `%d`" , instanceType , len ( content ) , len ( bytesBuffer2 . Bytes ( ) ) )
t . Errorf ( "%s: Expected content length to be `%d`, but instead found `%d`" , instanceType , len ( content ) , len ( bytesBuffer2 . Bytes ( ) ) )
}
}
}
}
// Wrapper for calling testPutObjectInSubdir for both XL and FS.
// Wrapper for calling testPutObjectInSubdir for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestPutObjectInSubdir ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestPutObjectInSubdir ( t * testing . T ) {
ExecObjectLayerTest ( c , testPutObjectInSubdir )
ExecObjectLayerTest ( t , testPutObjectInSubdir )
}
}
// Tests validate PutObject with subdirectory prefix.
// Tests validate PutObject with subdirectory prefix.
func testPutObjectInSubdir ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testPutObjectInSubdir ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
err := obj . MakeBucketWithLocation ( "bucket" , "" )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
uploadContent := ` The specified multipart upload does not exist . The upload ID might be invalid , or the multipart
uploadContent := ` The specified multipart upload does not exist . The upload ID might be invalid , or the multipart
@ -564,180 +561,180 @@ func testPutObjectInSubdir(obj ObjectLayer, instanceType string, c TestErrHandle
length := int64 ( len ( uploadContent ) )
length := int64 ( len ( uploadContent ) )
_ , err = obj . PutObject ( "bucket" , "dir1/dir2/object" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , length , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "dir1/dir2/object" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , length , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
var bytesBuffer bytes . Buffer
var bytesBuffer bytes . Buffer
err = obj . GetObject ( "bucket" , "dir1/dir2/object" , 0 , length , & bytesBuffer )
err = obj . GetObject ( "bucket" , "dir1/dir2/object" , 0 , length , & bytesBuffer )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( bytesBuffer . Bytes ( ) ) != len ( uploadContent ) {
if len ( bytesBuffer . Bytes ( ) ) != len ( uploadContent ) {
c . Errorf ( "%s: Expected length of downloaded data to be `%d`, but instead found `%d`" ,
t . Errorf ( "%s: Expected length of downloaded data to be `%d`, but instead found `%d`" ,
instanceType , len ( uploadContent ) , len ( bytesBuffer . Bytes ( ) ) )
instanceType , len ( uploadContent ) , len ( bytesBuffer . Bytes ( ) ) )
}
}
}
}
// Wrapper for calling testListBuckets for both XL and FS.
// Wrapper for calling testListBuckets for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestListBuckets ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestListBuckets ( t * testing . T ) {
ExecObjectLayerTest ( c , testListBuckets )
ExecObjectLayerTest ( t , testListBuckets )
}
}
// Tests validate ListBuckets.
// Tests validate ListBuckets.
func testListBuckets ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testListBuckets ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
// test empty list.
// test empty list.
buckets , err := obj . ListBuckets ( )
buckets , err := obj . ListBuckets ( )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( buckets ) != 0 {
if len ( buckets ) != 0 {
c . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 0 , len ( buckets ) )
t . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 0 , len ( buckets ) )
}
}
// add one and test exists.
// add one and test exists.
err = obj . MakeBucketWithLocation ( "bucket1" , "" )
err = obj . MakeBucketWithLocation ( "bucket1" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
buckets , err = obj . ListBuckets ( )
buckets , err = obj . ListBuckets ( )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( buckets ) != 1 {
if len ( buckets ) != 1 {
c . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 1 , len ( buckets ) )
t . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 1 , len ( buckets ) )
}
}
// add two and test exists.
// add two and test exists.
err = obj . MakeBucketWithLocation ( "bucket2" , "" )
err = obj . MakeBucketWithLocation ( "bucket2" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
buckets , err = obj . ListBuckets ( )
buckets , err = obj . ListBuckets ( )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( buckets ) != 2 {
if len ( buckets ) != 2 {
c . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 2 , len ( buckets ) )
t . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 2 , len ( buckets ) )
}
}
// add three and test exists + prefix.
// add three and test exists + prefix.
err = obj . MakeBucketWithLocation ( "bucket22" , "" )
err = obj . MakeBucketWithLocation ( "bucket22" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
buckets , err = obj . ListBuckets ( )
buckets , err = obj . ListBuckets ( )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( buckets ) != 3 {
if len ( buckets ) != 3 {
c . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 3 , len ( buckets ) )
t . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 3 , len ( buckets ) )
}
}
}
}
// Wrapper for calling testListBucketsOrder for both XL and FS.
// Wrapper for calling testListBucketsOrder for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestListBucketsOrder ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestListBucketsOrder ( t * testing . T ) {
ExecObjectLayerTest ( c , testListBucketsOrder )
ExecObjectLayerTest ( t , testListBucketsOrder )
}
}
// Tests validate the order of result of ListBuckets.
// Tests validate the order of result of ListBuckets.
func testListBucketsOrder ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testListBucketsOrder ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
// if implementation contains a map, order of map keys will vary.
// if implementation contains a map, order of map keys will vary.
// this ensures they return in the same order each time.
// this ensures they return in the same order each time.
// add one and test exists.
// add one and test exists.
err := obj . MakeBucketWithLocation ( "bucket1" , "" )
err := obj . MakeBucketWithLocation ( "bucket1" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
err = obj . MakeBucketWithLocation ( "bucket2" , "" )
err = obj . MakeBucketWithLocation ( "bucket2" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
buckets , err := obj . ListBuckets ( )
buckets , err := obj . ListBuckets ( )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if len ( buckets ) != 2 {
if len ( buckets ) != 2 {
c . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 2 , len ( buckets ) )
t . Errorf ( "%s: Expected number of bucket to be `%d`, but instead found `%d`" , instanceType , 2 , len ( buckets ) )
}
}
if buckets [ 0 ] . Name != "bucket1" {
if buckets [ 0 ] . Name != "bucket1" {
c . Errorf ( "%s: Expected bucket name to be `%s`, but instead found `%s`" , instanceType , "bucket1" , buckets [ 0 ] . Name )
t . Errorf ( "%s: Expected bucket name to be `%s`, but instead found `%s`" , instanceType , "bucket1" , buckets [ 0 ] . Name )
}
}
if buckets [ 1 ] . Name != "bucket2" {
if buckets [ 1 ] . Name != "bucket2" {
c . Errorf ( "%s: Expected bucket name to be `%s`, but instead found `%s`" , instanceType , "bucket2" , buckets [ 1 ] . Name )
t . Errorf ( "%s: Expected bucket name to be `%s`, but instead found `%s`" , instanceType , "bucket2" , buckets [ 1 ] . Name )
}
}
}
}
// Wrapper for calling testListObjectsTestsForNonExistantBucket for both XL and FS.
// Wrapper for calling testListObjectsTestsForNonExistantBucket for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestListObjectsTestsForNonExistantBucket ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestListObjectsTestsForNonExistantBucket ( t * testing . T ) {
ExecObjectLayerTest ( c , testListObjectsTestsForNonExistantBucket )
ExecObjectLayerTest ( t , testListObjectsTestsForNonExistantBucket )
}
}
// Tests validate that ListObjects operation on a non-existent bucket fails as expected.
// Tests validate that ListObjects operation on a non-existent bucket fails as expected.
func testListObjectsTestsForNonExistantBucket ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testListObjectsTestsForNonExistantBucket ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
result , err := obj . ListObjects ( "bucket" , "" , "" , "" , 1000 )
result , err := obj . ListObjects ( "bucket" , "" , "" , "" , 1000 )
if err == nil {
if err == nil {
c . Fatalf ( "%s: Expected error but found nil." , instanceType )
t . Fatalf ( "%s: Expected error but found nil." , instanceType )
}
}
if len ( result . Objects ) != 0 {
if len ( result . Objects ) != 0 {
c . Fatalf ( "%s: Expected number of objects in the result to be `%d`, but instead found `%d`" , instanceType , 0 , len ( result . Objects ) )
t . Fatalf ( "%s: Expected number of objects in the result to be `%d`, but instead found `%d`" , instanceType , 0 , len ( result . Objects ) )
}
}
if result . IsTruncated {
if result . IsTruncated {
c . Fatalf ( "%s: Expected IsTruncated to be `false`, but instead found it to be `%v`" , instanceType , result . IsTruncated )
t . Fatalf ( "%s: Expected IsTruncated to be `false`, but instead found it to be `%v`" , instanceType , result . IsTruncated )
}
}
if err . Error ( ) != "Bucket not found: bucket" {
if err . Error ( ) != "Bucket not found: bucket" {
c . Errorf ( "%s: Expected the error msg to be `%s`, but instead found `%s`" , instanceType , "Bucket not found: bucket" , err . Error ( ) )
t . Errorf ( "%s: Expected the error msg to be `%s`, but instead found `%s`" , instanceType , "Bucket not found: bucket" , err . Error ( ) )
}
}
}
}
// Wrapper for calling testNonExistantObjectInBucket for both XL and FS.
// Wrapper for calling testNonExistantObjectInBucket for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestNonExistantObjectInBucket ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestNonExistantObjectInBucket ( t * testing . T ) {
ExecObjectLayerTest ( c , testNonExistantObjectInBucket )
ExecObjectLayerTest ( t , testNonExistantObjectInBucket )
}
}
// Tests validate that GetObject fails on a non-existent bucket as expected.
// Tests validate that GetObject fails on a non-existent bucket as expected.
func testNonExistantObjectInBucket ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testNonExistantObjectInBucket ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
err := obj . MakeBucketWithLocation ( "bucket" , "" )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
_ , err = obj . GetObjectInfo ( "bucket" , "dir1" )
_ , err = obj . GetObjectInfo ( "bucket" , "dir1" )
if err == nil {
if err == nil {
c . Fatalf ( "%s: Expected error but found nil" , instanceType )
t . Fatalf ( "%s: Expected error but found nil" , instanceType )
}
}
if isErrObjectNotFound ( err ) {
if isErrObjectNotFound ( err ) {
if err . Error ( ) != "Object not found: bucket#dir1" {
if err . Error ( ) != "Object not found: bucket#dir1" {
c . Errorf ( "%s: Expected the Error message to be `%s`, but instead found `%s`" , instanceType , "Object not found: bucket#dir1" , err . Error ( ) )
t . Errorf ( "%s: Expected the Error message to be `%s`, but instead found `%s`" , instanceType , "Object not found: bucket#dir1" , err . Error ( ) )
}
}
} else {
} else {
if err . Error ( ) != "fails" {
if err . Error ( ) != "fails" {
c . Errorf ( "%s: Expected the Error message to be `%s`, but instead found it to be `%s`" , instanceType , "fails" , err . Error ( ) )
t . Errorf ( "%s: Expected the Error message to be `%s`, but instead found it to be `%s`" , instanceType , "fails" , err . Error ( ) )
}
}
}
}
}
}
// Wrapper for calling testGetDirectoryReturnsObjectNotFound for both XL and FS.
// Wrapper for calling testGetDirectoryReturnsObjectNotFound for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestGetDirectoryReturnsObjectNotFound ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestGetDirectoryReturnsObjectNotFound ( t * testing . T ) {
ExecObjectLayerTest ( c , testGetDirectoryReturnsObjectNotFound )
ExecObjectLayerTest ( t , testGetDirectoryReturnsObjectNotFound )
}
}
// Tests validate that GetObject on an existing directory fails as expected.
// Tests validate that GetObject on an existing directory fails as expected.
func testGetDirectoryReturnsObjectNotFound ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testGetDirectoryReturnsObjectNotFound ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
bucketName := "bucket"
bucketName := "bucket"
err := obj . MakeBucketWithLocation ( bucketName , "" )
err := obj . MakeBucketWithLocation ( bucketName , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
content := "One or more of the specified parts could not be found. The part might not have been uploaded, or the specified entity tag might not have matched the part's entity tag."
content := "One or more of the specified parts could not be found. The part might not have been uploaded, or the specified entity tag might not have matched the part's entity tag."
length := int64 ( len ( content ) )
length := int64 ( len ( content ) )
_ , err = obj . PutObject ( bucketName , "dir1/dir3/object" , NewHashReader ( bytes . NewBufferString ( content ) , length , "" , "" ) , nil )
_ , err = obj . PutObject ( bucketName , "dir1/dir3/object" , NewHashReader ( bytes . NewBufferString ( content ) , length , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
testCases := [ ] struct {
testCases := [ ] struct {
@ -759,35 +756,35 @@ func testGetDirectoryReturnsObjectNotFound(obj ObjectLayer, instanceType string,
if expectedErr != nil {
if expectedErr != nil {
expectedErr = errorCause ( expectedErr )
expectedErr = errorCause ( expectedErr )
if expectedErr . Error ( ) != testCase . err . Error ( ) {
if expectedErr . Error ( ) != testCase . err . Error ( ) {
c . Errorf ( "Test %d, %s: Expected error %s, got %s" , i + 1 , instanceType , testCase . err , expectedErr )
t . Errorf ( "Test %d, %s: Expected error %s, got %s" , i + 1 , instanceType , testCase . err , expectedErr )
}
}
}
}
}
}
}
}
// Wrapper for calling testContentType for both XL and FS.
// Wrapper for calling testContentType for both XL and FS.
func ( s * ObjectLayerAPISuite ) TestContentType ( c * C ) {
func ( s * ObjectLayerAPISuite ) TestContentType ( t * testing . T ) {
ExecObjectLayerTest ( c , testContentType )
ExecObjectLayerTest ( t , testContentType )
}
}
// Test content-type.
// Test content-type.
func testContentType ( obj ObjectLayer , instanceType string , c TestErrHandler ) {
func testContentType ( obj ObjectLayer , instanceType string , t TestErrHandler ) {
err := obj . MakeBucketWithLocation ( "bucket" , "" )
err := obj . MakeBucketWithLocation ( "bucket" , "" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
uploadContent := "The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed."
uploadContent := "The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed."
// Test empty.
// Test empty.
_ , err = obj . PutObject ( "bucket" , "minio.png" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
_ , err = obj . PutObject ( "bucket" , "minio.png" , NewHashReader ( bytes . NewBufferString ( uploadContent ) , int64 ( len ( uploadContent ) ) , "" , "" ) , nil )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
objInfo , err := obj . GetObjectInfo ( "bucket" , "minio.png" )
objInfo , err := obj . GetObjectInfo ( "bucket" , "minio.png" )
if err != nil {
if err != nil {
c . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
t . Fatalf ( "%s: <ERROR> %s" , instanceType , err )
}
}
if objInfo . ContentType != "image/png" {
if objInfo . ContentType != "image/png" {
c . Errorf ( "%s: Expected Content type to be `%s`, but instead found `%s`" , instanceType , "image/png" , objInfo . ContentType )
t . Errorf ( "%s: Expected Content type to be `%s`, but instead found `%s`" , instanceType , "image/png" , objInfo . ContentType )
}
}
}
}