2017-10-05 15:24:45 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2017 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
package s3
|
2017-10-05 15:24:45 -04:00
|
|
|
|
|
|
|
import (
|
2017-12-05 20:58:09 -05:00
|
|
|
"fmt"
|
2017-10-05 15:24:45 -04:00
|
|
|
"testing"
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
miniogo "github.com/minio/minio-go"
|
2017-10-22 01:30:34 -04:00
|
|
|
"github.com/minio/minio/pkg/hash"
|
2017-12-05 20:58:09 -05:00
|
|
|
|
|
|
|
minio "github.com/minio/minio/cmd"
|
2017-10-05 15:24:45 -04:00
|
|
|
)
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
func errResponse(code string) miniogo.ErrorResponse {
|
|
|
|
return miniogo.ErrorResponse{
|
2017-10-05 15:24:45 -04:00
|
|
|
Code: code,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3ToObjectError(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
inputErr error
|
|
|
|
expectedErr error
|
|
|
|
bucket, object string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
inputErr: errResponse("BucketAlreadyOwnedByYou"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketAlreadyOwnedByYou{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("BucketNotEmpty"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketNotEmpty{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("InvalidBucketName"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketNameInvalid{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
2018-10-17 12:20:58 -04:00
|
|
|
{
|
|
|
|
inputErr: errResponse("InvalidPart"),
|
|
|
|
expectedErr: minio.InvalidPart{},
|
|
|
|
},
|
2017-10-05 15:24:45 -04:00
|
|
|
{
|
|
|
|
inputErr: errResponse("NoSuchBucketPolicy"),
|
2018-04-24 18:53:30 -04:00
|
|
|
expectedErr: minio.BucketPolicyNotFound{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("NoSuchBucket"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketNotFound{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
2017-12-05 20:58:09 -05:00
|
|
|
// with empty Object in miniogo.ErrorRepsonse, NoSuchKey
|
2017-10-05 15:24:45 -04:00
|
|
|
// is interpreted as BucketNotFound
|
|
|
|
{
|
|
|
|
inputErr: errResponse("NoSuchKey"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketNotFound{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("NoSuchUpload"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.InvalidUploadID{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("XMinioInvalidObjectName"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.ObjectNameInvalid{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("AccessDenied"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.PrefixAccessDenied{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("XAmzContentSHA256Mismatch"),
|
2017-10-22 01:30:34 -04:00
|
|
|
expectedErr: hash.SHA256Mismatch{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("EntityTooSmall"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.PartTooSmall{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: nil,
|
|
|
|
expectedErr: nil,
|
|
|
|
},
|
|
|
|
// Special test case for NoSuchKey with object name
|
|
|
|
{
|
2017-12-05 20:58:09 -05:00
|
|
|
inputErr: miniogo.ErrorResponse{
|
2017-10-05 15:24:45 -04:00
|
|
|
Code: "NoSuchKey",
|
|
|
|
},
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.ObjectNotFound{
|
|
|
|
Bucket: "bucket",
|
|
|
|
Object: "object",
|
|
|
|
},
|
|
|
|
bucket: "bucket",
|
|
|
|
object: "object",
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// N B error values that aren't of expected types
|
|
|
|
// should be left untouched.
|
|
|
|
// Special test case for error that is not of type
|
2017-12-05 20:58:09 -05:00
|
|
|
// miniogo.ErrorResponse
|
2017-10-05 15:24:45 -04:00
|
|
|
{
|
2017-12-05 20:58:09 -05:00
|
|
|
inputErr: fmt.Errorf("not a minio.ErrorResponse"),
|
|
|
|
expectedErr: fmt.Errorf("not a minio.ErrorResponse"),
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
2018-04-05 18:04:40 -04:00
|
|
|
actualErr := minio.ErrorRespToObjectError(tc.inputErr, tc.bucket, tc.object)
|
2018-04-10 12:36:37 -04:00
|
|
|
if actualErr != nil && tc.expectedErr != nil && actualErr.Error() != tc.expectedErr.Error() {
|
2018-04-05 18:04:40 -04:00
|
|
|
t.Errorf("Test case %d: Expected error %v but received error %v", i+1, tc.expectedErr, actualErr)
|
2017-10-05 15:24:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|