diff --git a/pkg/miniogw/logging/logging.go b/pkg/miniogw/logging/logging.go index b379cd6ff..aaac034f4 100644 --- a/pkg/miniogw/logging/logging.go +++ b/pkg/miniogw/logging/logging.go @@ -6,6 +6,7 @@ package logging import ( context "context" io "io" + "reflect" "time" minio "github.com/minio/minio/cmd" @@ -41,20 +42,27 @@ type olLogWrap struct { logger ErrorLogger } -// ErrorLogger logs a templated error message +// ErrorLogger logs a templated error message. type ErrorLogger interface { Errorf(template string, args ...interface{}) } -func (ol *olLogWrap) wrap(err error) error { - if err != nil { +// minioError checks if the given error is a minio error. +func minioError(err error) bool { + return reflect.TypeOf(err).ConvertibleTo(reflect.TypeOf(minio.GenericError{})) +} + +// log unexpected errors, i.e. non-minio errors. It will return the given error +// to allow method chaining. +func (ol *olLogWrap) log(err error) error { + if err != nil && !minioError(err) { ol.logger.Errorf(errTemplate, err) } return err } func (ol *olLogWrap) Shutdown(ctx context.Context) error { - return ol.wrap(ol.ol.Shutdown(ctx)) + return ol.log(ol.ol.Shutdown(ctx)) } func (ol *olLogWrap) StorageInfo(ctx context.Context) minio.StorageInfo { @@ -63,34 +71,23 @@ func (ol *olLogWrap) StorageInfo(ctx context.Context) minio.StorageInfo { func (ol *olLogWrap) MakeBucketWithLocation(ctx context.Context, bucket string, location string) error { - err := ol.ol.MakeBucketWithLocation(ctx, bucket, location) - if _, ok := err.(minio.BucketAlreadyExists); ok { - return err - } - return ol.wrap(err) + return ol.log(ol.ol.MakeBucketWithLocation(ctx, bucket, location)) } func (ol *olLogWrap) GetBucketInfo(ctx context.Context, bucket string) ( bucketInfo minio.BucketInfo, err error) { bucketInfo, err = ol.ol.GetBucketInfo(ctx, bucket) - return bucketInfo, ol.wrap(err) + return bucketInfo, ol.log(err) } func (ol *olLogWrap) ListBuckets(ctx context.Context) ( buckets []minio.BucketInfo, err error) { buckets, err = ol.ol.ListBuckets(ctx) - return buckets, ol.wrap(err) + return buckets, ol.log(err) } func (ol *olLogWrap) DeleteBucket(ctx context.Context, bucket string) error { - err := ol.ol.DeleteBucket(ctx, bucket) - if _, ok := err.(minio.BucketNotEmpty); ok { - return err - } - if _, ok := err.(minio.BucketNotFound); ok { - return err - } - return ol.wrap(err) + return ol.log(ol.ol.DeleteBucket(ctx, bucket)) } func (ol *olLogWrap) ListObjects(ctx context.Context, @@ -98,7 +95,7 @@ func (ol *olLogWrap) ListObjects(ctx context.Context, result minio.ListObjectsInfo, err error) { result, err = ol.ol.ListObjects(ctx, bucket, prefix, marker, delimiter, maxKeys) - return result, ol.wrap(err) + return result, ol.log(err) } func (ol *olLogWrap) ListObjectsV2(ctx context.Context, @@ -107,29 +104,26 @@ func (ol *olLogWrap) ListObjectsV2(ctx context.Context, err error) { result, err = ol.ol.ListObjectsV2(ctx, bucket, prefix, continuationToken, delimiter, maxKeys, fetchOwner, startAfter) - return result, ol.wrap(err) + return result, ol.log(err) } func (ol *olLogWrap) GetObject(ctx context.Context, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string) (err error) { - return ol.wrap(ol.ol.GetObject(ctx, bucket, object, startOffset, length, + return ol.log(ol.ol.GetObject(ctx, bucket, object, startOffset, length, writer, etag)) } func (ol *olLogWrap) GetObjectInfo(ctx context.Context, bucket, object string) ( objInfo minio.ObjectInfo, err error) { objInfo, err = ol.ol.GetObjectInfo(ctx, bucket, object) - if _, ok := err.(minio.ObjectNotFound); ok { - return objInfo, err - } - return objInfo, ol.wrap(err) + return objInfo, ol.log(err) } func (ol *olLogWrap) PutObject(ctx context.Context, bucket, object string, data *hash.Reader, metadata map[string]string) (objInfo minio.ObjectInfo, err error) { objInfo, err = ol.ol.PutObject(ctx, bucket, object, data, metadata) - return objInfo, ol.wrap(err) + return objInfo, ol.log(err) } func (ol *olLogWrap) CopyObject(ctx context.Context, @@ -137,12 +131,12 @@ func (ol *olLogWrap) CopyObject(ctx context.Context, srcInfo minio.ObjectInfo) (objInfo minio.ObjectInfo, err error) { objInfo, err = ol.ol.CopyObject(ctx, srcBucket, srcObject, destBucket, destObject, srcInfo) - return objInfo, ol.wrap(err) + return objInfo, ol.log(err) } func (ol *olLogWrap) DeleteObject(ctx context.Context, bucket, object string) ( err error) { - return ol.wrap(ol.ol.DeleteObject(ctx, bucket, object)) + return ol.log(ol.ol.DeleteObject(ctx, bucket, object)) } func (ol *olLogWrap) ListMultipartUploads(ctx context.Context, @@ -150,14 +144,14 @@ func (ol *olLogWrap) ListMultipartUploads(ctx context.Context, result minio.ListMultipartsInfo, err error) { result, err = ol.ol.ListMultipartUploads(ctx, bucket, prefix, keyMarker, uploadIDMarker, delimiter, maxUploads) - return result, ol.wrap(err) + return result, ol.log(err) } func (ol *olLogWrap) NewMultipartUpload(ctx context.Context, bucket, object string, metadata map[string]string) (uploadID string, err error) { uploadID, err = ol.ol.NewMultipartUpload(ctx, bucket, object, metadata) - return uploadID, ol.wrap(err) + return uploadID, ol.log(err) } func (ol *olLogWrap) CopyObjectPart(ctx context.Context, @@ -166,14 +160,14 @@ func (ol *olLogWrap) CopyObjectPart(ctx context.Context, info minio.PartInfo, err error) { info, err = ol.ol.CopyObjectPart(ctx, srcBucket, srcObject, destBucket, destObject, uploadID, partID, startOffset, length, srcInfo) - return info, ol.wrap(err) + return info, ol.log(err) } func (ol *olLogWrap) PutObjectPart(ctx context.Context, bucket, object, uploadID string, partID int, data *hash.Reader) ( info minio.PartInfo, err error) { info, err = ol.ol.PutObjectPart(ctx, bucket, object, uploadID, partID, data) - return info, ol.wrap(err) + return info, ol.log(err) } func (ol *olLogWrap) ListObjectParts(ctx context.Context, @@ -181,12 +175,12 @@ func (ol *olLogWrap) ListObjectParts(ctx context.Context, result minio.ListPartsInfo, err error) { result, err = ol.ol.ListObjectParts(ctx, bucket, object, uploadID, partNumberMarker, maxParts) - return result, ol.wrap(err) + return result, ol.log(err) } func (ol *olLogWrap) AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string) error { - return ol.wrap(ol.ol.AbortMultipartUpload(ctx, bucket, object, uploadID)) + return ol.log(ol.ol.AbortMultipartUpload(ctx, bucket, object, uploadID)) } func (ol *olLogWrap) CompleteMultipartUpload(ctx context.Context, @@ -194,35 +188,35 @@ func (ol *olLogWrap) CompleteMultipartUpload(ctx context.Context, objInfo minio.ObjectInfo, err error) { objInfo, err = ol.ol.CompleteMultipartUpload(ctx, bucket, object, uploadID, uploadedParts) - return objInfo, ol.wrap(err) + return objInfo, ol.log(err) } func (ol *olLogWrap) ReloadFormat(ctx context.Context, dryRun bool) error { - return ol.wrap(ol.ol.ReloadFormat(ctx, dryRun)) + return ol.log(ol.ol.ReloadFormat(ctx, dryRun)) } func (ol *olLogWrap) HealFormat(ctx context.Context, dryRun bool) ( madmin.HealResultItem, error) { rv, err := ol.ol.HealFormat(ctx, dryRun) - return rv, ol.wrap(err) + return rv, ol.log(err) } func (ol *olLogWrap) HealBucket(ctx context.Context, bucket string, dryRun bool) ([]madmin.HealResultItem, error) { rv, err := ol.ol.HealBucket(ctx, bucket, dryRun) - return rv, ol.wrap(err) + return rv, ol.log(err) } func (ol *olLogWrap) HealObject(ctx context.Context, bucket, object string, dryRun bool) (madmin.HealResultItem, error) { rv, err := ol.ol.HealObject(ctx, bucket, object, dryRun) - return rv, ol.wrap(err) + return rv, ol.log(err) } func (ol *olLogWrap) ListBucketsHeal(ctx context.Context) ( buckets []minio.BucketInfo, err error) { buckets, err = ol.ol.ListBucketsHeal(ctx) - return buckets, ol.wrap(err) + return buckets, ol.log(err) } func (ol *olLogWrap) ListObjectsHeal(ctx context.Context, @@ -230,33 +224,33 @@ func (ol *olLogWrap) ListObjectsHeal(ctx context.Context, minio.ListObjectsInfo, error) { rv, err := ol.ol.ListObjectsHeal(ctx, bucket, prefix, marker, delimiter, maxKeys) - return rv, ol.wrap(err) + return rv, ol.log(err) } func (ol *olLogWrap) ListLocks(ctx context.Context, bucket, prefix string, duration time.Duration) ([]minio.VolumeLockInfo, error) { rv, err := ol.ol.ListLocks(ctx, bucket, prefix, duration) - return rv, ol.wrap(err) + return rv, ol.log(err) } func (ol *olLogWrap) ClearLocks(ctx context.Context, lockInfos []minio.VolumeLockInfo) error { - return ol.wrap(ol.ol.ClearLocks(ctx, lockInfos)) + return ol.log(ol.ol.ClearLocks(ctx, lockInfos)) } func (ol *olLogWrap) SetBucketPolicy(ctx context.Context, n string, p *policy.Policy) error { - return ol.wrap(ol.ol.SetBucketPolicy(ctx, n, p)) + return ol.log(ol.ol.SetBucketPolicy(ctx, n, p)) } func (ol *olLogWrap) GetBucketPolicy(ctx context.Context, n string) ( *policy.Policy, error) { p, err := ol.ol.GetBucketPolicy(ctx, n) - return p, ol.wrap(err) + return p, ol.log(err) } func (ol *olLogWrap) DeleteBucketPolicy(ctx context.Context, n string) error { - return ol.wrap(ol.ol.DeleteBucketPolicy(ctx, n)) + return ol.log(ol.ol.DeleteBucketPolicy(ctx, n)) } func (ol *olLogWrap) IsNotificationSupported() bool { diff --git a/pkg/miniogw/logging/logging_test.go b/pkg/miniogw/logging/logging_test.go index 1d9f6d146..e6f3a89f8 100644 --- a/pkg/miniogw/logging/logging_test.go +++ b/pkg/miniogw/logging/logging_test.go @@ -45,6 +45,7 @@ const ( var ( ctx = context.Background() ErrTest = errors.New(testError) + ErrMinio = minio.BucketNotFound{} metadata = map[string]string{"key": "value"} ) @@ -115,7 +116,12 @@ func TestShutdown(t *testing.T) { mol.EXPECT().Shutdown(ctx).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.Shutdown(ctx) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().Shutdown(ctx).Return(ErrMinio) + err = ol.Shutdown(ctx) + assert.Error(t, err, ErrMinio.Error()) } func TestStorageInfo(t *testing.T) { @@ -147,7 +153,12 @@ func TestMakeBucketWithLocation(t *testing.T) { mol.EXPECT().MakeBucketWithLocation(ctx, bucket, location).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.MakeBucketWithLocation(ctx, bucket, location) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().MakeBucketWithLocation(ctx, bucket, location).Return(ErrMinio) + err = ol.MakeBucketWithLocation(ctx, bucket, location) + assert.Error(t, err, ErrMinio.Error()) } func TestGetBucketInfo(t *testing.T) { @@ -166,7 +177,13 @@ func TestGetBucketInfo(t *testing.T) { mol.EXPECT().GetBucketInfo(ctx, bucket).Return(minio.BucketInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) info, err = ol.GetBucketInfo(ctx, bucket) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.BucketInfo{}, info) + + // Minio error returned + mol.EXPECT().GetBucketInfo(ctx, bucket).Return(minio.BucketInfo{}, ErrMinio) + info, err = ol.GetBucketInfo(ctx, bucket) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.BucketInfo{}, info) } @@ -186,7 +203,13 @@ func TestListBuckets(t *testing.T) { mol.EXPECT().ListBuckets(ctx).Return([]minio.BucketInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.ListBuckets(ctx) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, []minio.BucketInfo{}, list) + + // Minio error returned + mol.EXPECT().ListBuckets(ctx).Return([]minio.BucketInfo{}, ErrMinio) + list, err = ol.ListBuckets(ctx) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, []minio.BucketInfo{}, list) } @@ -205,7 +228,12 @@ func TestDeleteBucket(t *testing.T) { mol.EXPECT().DeleteBucket(ctx, bucket).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.DeleteBucket(ctx, bucket) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().DeleteBucket(ctx, bucket).Return(ErrMinio) + err = ol.DeleteBucket(ctx, bucket) + assert.Error(t, err, ErrMinio.Error()) } func TestListObjects(t *testing.T) { @@ -226,7 +254,14 @@ func TestListObjects(t *testing.T) { Return(minio.ListObjectsInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.ListObjects(ctx, bucket, prefix, marker, delimiter, maxKeys) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ListObjectsInfo{}, list) + + // Minio error returned + mol.EXPECT().ListObjects(ctx, bucket, prefix, marker, delimiter, maxKeys). + Return(minio.ListObjectsInfo{}, ErrMinio) + list, err = ol.ListObjects(ctx, bucket, prefix, marker, delimiter, maxKeys) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ListObjectsInfo{}, list) } @@ -254,7 +289,15 @@ func TestListObjectsV2(t *testing.T) { logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.ListObjectsV2(ctx, bucket, prefix, marker, delimiter, maxKeys, owner, startAfter) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ListObjectsV2Info{}, list) + + // Minio error returned + mol.EXPECT().ListObjectsV2(ctx, bucket, prefix, marker, delimiter, maxKeys, + owner, startAfter).Return(minio.ListObjectsV2Info{}, ErrMinio) + list, err = ol.ListObjectsV2(ctx, bucket, prefix, marker, delimiter, + maxKeys, owner, startAfter) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ListObjectsV2Info{}, list) } @@ -276,7 +319,12 @@ func TestGetObject(t *testing.T) { mol.EXPECT().GetObject(ctx, bucket, object, offset, length, w, etag).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.GetObject(ctx, bucket, object, offset, length, w, etag) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().GetObject(ctx, bucket, object, offset, length, w, etag).Return(ErrMinio) + err = ol.GetObject(ctx, bucket, object, offset, length, w, etag) + assert.Error(t, err, ErrMinio.Error()) } func TestGetObjectInfo(t *testing.T) { @@ -295,7 +343,13 @@ func TestGetObjectInfo(t *testing.T) { mol.EXPECT().GetObjectInfo(ctx, bucket, object).Return(minio.ObjectInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) info, err = ol.GetObjectInfo(ctx, bucket, object) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ObjectInfo{}, info) + + // Minio error returned + mol.EXPECT().GetObjectInfo(ctx, bucket, object).Return(minio.ObjectInfo{}, ErrMinio) + info, err = ol.GetObjectInfo(ctx, bucket, object) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ObjectInfo{}, info) } @@ -317,7 +371,13 @@ func TestPutObject(t *testing.T) { mol.EXPECT().PutObject(ctx, bucket, object, data, metadata).Return(minio.ObjectInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) info, err = ol.PutObject(ctx, bucket, object, data, metadata) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ObjectInfo{}, info) + + // Minio error returned + mol.EXPECT().PutObject(ctx, bucket, object, data, metadata).Return(minio.ObjectInfo{}, ErrMinio) + info, err = ol.PutObject(ctx, bucket, object, data, metadata) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ObjectInfo{}, info) } @@ -339,7 +399,14 @@ func TestCopyObject(t *testing.T) { Return(minio.ObjectInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) info, err = ol.CopyObject(ctx, bucket, object, destBucket, destObject, objInfo) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ObjectInfo{}, info) + + // Minio error returned + mol.EXPECT().CopyObject(ctx, bucket, object, destBucket, destObject, objInfo). + Return(minio.ObjectInfo{}, ErrMinio) + info, err = ol.CopyObject(ctx, bucket, object, destBucket, destObject, objInfo) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ObjectInfo{}, info) } @@ -358,7 +425,12 @@ func TestDeleteObject(t *testing.T) { mol.EXPECT().DeleteObject(ctx, bucket, object).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.DeleteObject(ctx, bucket, object) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().DeleteObject(ctx, bucket, object).Return(ErrMinio) + err = ol.DeleteObject(ctx, bucket, object) + assert.Error(t, err, ErrMinio.Error()) } func TestListMultipartUploads(t *testing.T) { @@ -385,7 +457,15 @@ func TestListMultipartUploads(t *testing.T) { logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.ListMultipartUploads(ctx, bucket, prefix, marker, uidMarker, delimiter, maxKeys) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ListMultipartsInfo{}, list) + + // Minio error returned + mol.EXPECT().ListMultipartUploads(ctx, bucket, prefix, marker, uidMarker, + delimiter, maxKeys).Return(minio.ListMultipartsInfo{}, ErrMinio) + list, err = ol.ListMultipartUploads(ctx, bucket, prefix, marker, uidMarker, + delimiter, maxKeys) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ListMultipartsInfo{}, list) } @@ -405,7 +485,13 @@ func TestNewMultipartUpload(t *testing.T) { mol.EXPECT().NewMultipartUpload(ctx, bucket, object, metadata).Return("", ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) id, err = ol.NewMultipartUpload(ctx, bucket, object, metadata) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, "", id) + + // Minio error returned + mol.EXPECT().NewMultipartUpload(ctx, bucket, object, metadata).Return("", ErrMinio) + id, err = ol.NewMultipartUpload(ctx, bucket, object, metadata) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, "", id) } @@ -429,7 +515,15 @@ func TestCopyObjectPart(t *testing.T) { logger.EXPECT().Errorf(errTemplate, ErrTest) info, err = ol.CopyObjectPart(ctx, bucket, object, destBucket, destObject, uploadID, partID, offset, length, objInfo) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.PartInfo{}, info) + + // Minio error returned + mol.EXPECT().CopyObjectPart(ctx, bucket, object, destBucket, destObject, + uploadID, partID, offset, length, objInfo).Return(minio.PartInfo{}, ErrMinio) + info, err = ol.CopyObjectPart(ctx, bucket, object, destBucket, destObject, + uploadID, partID, offset, length, objInfo) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.PartInfo{}, info) } @@ -453,7 +547,14 @@ func TestPutObjectPart(t *testing.T) { Return(minio.PartInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) info, err = ol.PutObjectPart(ctx, bucket, object, uploadID, partID, data) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.PartInfo{}, info) + + // Minio error returned + mol.EXPECT().PutObjectPart(ctx, bucket, object, uploadID, partID, data). + Return(minio.PartInfo{}, ErrMinio) + info, err = ol.PutObjectPart(ctx, bucket, object, uploadID, partID, data) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.PartInfo{}, info) } @@ -475,7 +576,14 @@ func TestListObjectParts(t *testing.T) { Return(minio.ListPartsInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.ListObjectParts(ctx, bucket, object, uploadID, partMarker, maxKeys) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ListPartsInfo{}, list) + + // Minio error returned + mol.EXPECT().ListObjectParts(ctx, bucket, object, uploadID, partMarker, maxKeys). + Return(minio.ListPartsInfo{}, ErrMinio) + list, err = ol.ListObjectParts(ctx, bucket, object, uploadID, partMarker, maxKeys) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ListPartsInfo{}, list) } @@ -494,7 +602,12 @@ func TestAbortMultipartUpload(t *testing.T) { mol.EXPECT().AbortMultipartUpload(ctx, bucket, object, uploadID).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.AbortMultipartUpload(ctx, bucket, object, uploadID) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().AbortMultipartUpload(ctx, bucket, object, uploadID).Return(ErrMinio) + err = ol.AbortMultipartUpload(ctx, bucket, object, uploadID) + assert.Error(t, err, ErrMinio.Error()) } func TestCompleteMultipartUpload(t *testing.T) { @@ -517,7 +630,14 @@ func TestCompleteMultipartUpload(t *testing.T) { Return(minio.ObjectInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) info, err = ol.CompleteMultipartUpload(ctx, bucket, object, uploadID, parts) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ObjectInfo{}, info) + + // Minio error returned + mol.EXPECT().CompleteMultipartUpload(ctx, bucket, object, uploadID, parts). + Return(minio.ObjectInfo{}, ErrMinio) + info, err = ol.CompleteMultipartUpload(ctx, bucket, object, uploadID, parts) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ObjectInfo{}, info) } @@ -536,7 +656,12 @@ func TestReloadFormat(t *testing.T) { mol.EXPECT().ReloadFormat(ctx, dryRun).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.ReloadFormat(ctx, dryRun) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().ReloadFormat(ctx, dryRun).Return(ErrMinio) + err = ol.ReloadFormat(ctx, dryRun) + assert.Error(t, err, ErrMinio.Error()) } func TestHealFormat(t *testing.T) { @@ -555,7 +680,13 @@ func TestHealFormat(t *testing.T) { mol.EXPECT().HealFormat(ctx, dryRun).Return(madmin.HealResultItem{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) item, err = ol.HealFormat(ctx, dryRun) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, madmin.HealResultItem{}, item) + + // Minio error returned + mol.EXPECT().HealFormat(ctx, dryRun).Return(madmin.HealResultItem{}, ErrMinio) + item, err = ol.HealFormat(ctx, dryRun) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, madmin.HealResultItem{}, item) } @@ -575,7 +706,13 @@ func TestHealBucket(t *testing.T) { mol.EXPECT().HealBucket(ctx, bucket, dryRun).Return([]madmin.HealResultItem{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.HealBucket(ctx, bucket, dryRun) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, []madmin.HealResultItem{}, list) + + // Minio error returned + mol.EXPECT().HealBucket(ctx, bucket, dryRun).Return([]madmin.HealResultItem{}, ErrMinio) + list, err = ol.HealBucket(ctx, bucket, dryRun) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, []madmin.HealResultItem{}, list) } @@ -595,7 +732,13 @@ func TestHealObject(t *testing.T) { mol.EXPECT().HealObject(ctx, bucket, object, dryRun).Return(madmin.HealResultItem{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) item, err = ol.HealObject(ctx, bucket, object, dryRun) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, madmin.HealResultItem{}, item) + + // Minio error returned + mol.EXPECT().HealObject(ctx, bucket, object, dryRun).Return(madmin.HealResultItem{}, ErrMinio) + item, err = ol.HealObject(ctx, bucket, object, dryRun) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, madmin.HealResultItem{}, item) } @@ -615,7 +758,13 @@ func TestListBucketsHeal(t *testing.T) { mol.EXPECT().ListBucketsHeal(ctx).Return([]minio.BucketInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.ListBucketsHeal(ctx) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, []minio.BucketInfo{}, list) + + // Minio error returned + mol.EXPECT().ListBucketsHeal(ctx).Return([]minio.BucketInfo{}, ErrMinio) + list, err = ol.ListBucketsHeal(ctx) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, []minio.BucketInfo{}, list) } @@ -637,7 +786,14 @@ func TestListObjectsHeal(t *testing.T) { Return(minio.ListObjectsInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.ListObjectsHeal(ctx, bucket, prefix, marker, delimiter, maxKeys) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, minio.ListObjectsInfo{}, list) + + // Minio error returned + mol.EXPECT().ListObjectsHeal(ctx, bucket, prefix, marker, delimiter, maxKeys). + Return(minio.ListObjectsInfo{}, ErrMinio) + list, err = ol.ListObjectsHeal(ctx, bucket, prefix, marker, delimiter, maxKeys) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, minio.ListObjectsInfo{}, list) } @@ -658,7 +814,14 @@ func TestListLocks(t *testing.T) { Return([]minio.VolumeLockInfo{}, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) list, err = ol.ListLocks(ctx, bucket, prefix, duration) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Equal(t, []minio.VolumeLockInfo{}, list) + + // Minio error returned + mol.EXPECT().ListLocks(ctx, bucket, prefix, duration). + Return([]minio.VolumeLockInfo{}, ErrMinio) + list, err = ol.ListLocks(ctx, bucket, prefix, duration) + assert.Error(t, err, ErrMinio.Error()) assert.Equal(t, []minio.VolumeLockInfo{}, list) } @@ -677,7 +840,12 @@ func TestClearLocks(t *testing.T) { mol.EXPECT().ClearLocks(ctx, lockList).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.ClearLocks(ctx, lockList) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().ClearLocks(ctx, lockList).Return(ErrMinio) + err = ol.ClearLocks(ctx, lockList) + assert.Error(t, err, ErrMinio.Error()) } func TestSetBucketPolicy(t *testing.T) { @@ -695,7 +863,12 @@ func TestSetBucketPolicy(t *testing.T) { mol.EXPECT().SetBucketPolicy(ctx, n, plcy).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.SetBucketPolicy(ctx, n, plcy) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().SetBucketPolicy(ctx, n, plcy).Return(ErrMinio) + err = ol.SetBucketPolicy(ctx, n, plcy) + assert.Error(t, err, ErrMinio.Error()) } func TestGetBucketPolicy(t *testing.T) { @@ -714,7 +887,13 @@ func TestGetBucketPolicy(t *testing.T) { mol.EXPECT().GetBucketPolicy(ctx, n).Return(nil, ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) p, err = ol.GetBucketPolicy(ctx, n) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + assert.Nil(t, p) + + // Minio error returned + mol.EXPECT().GetBucketPolicy(ctx, n).Return(nil, ErrMinio) + p, err = ol.GetBucketPolicy(ctx, n) + assert.Error(t, err, ErrMinio.Error()) assert.Nil(t, p) } @@ -733,7 +912,12 @@ func TestDeleteBucketPolicy(t *testing.T) { mol.EXPECT().DeleteBucketPolicy(ctx, n).Return(ErrTest) logger.EXPECT().Errorf(errTemplate, ErrTest) err = ol.DeleteBucketPolicy(ctx, n) - assert.Error(t, err, testError) + assert.Error(t, err, ErrTest.Error()) + + // Minio error returned + mol.EXPECT().DeleteBucketPolicy(ctx, n).Return(ErrMinio) + err = ol.DeleteBucketPolicy(ctx, n) + assert.Error(t, err, ErrMinio.Error()) } func TestIsNotificationSupported(t *testing.T) {