2016-09-15 04:44:19 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
2017-10-22 01:30:34 -04:00
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/hash"
|
2016-09-15 04:44:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIErrCode(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
err error
|
|
|
|
errCode APIErrorCode
|
|
|
|
}{
|
|
|
|
// Valid cases.
|
|
|
|
{
|
2017-10-22 01:30:34 -04:00
|
|
|
hash.BadDigest{},
|
2016-09-15 04:44:19 -04:00
|
|
|
ErrBadDigest,
|
|
|
|
},
|
2017-10-22 01:30:34 -04:00
|
|
|
{
|
|
|
|
hash.SHA256Mismatch{},
|
|
|
|
ErrContentSHA256Mismatch,
|
|
|
|
},
|
2016-09-15 04:44:19 -04:00
|
|
|
{
|
|
|
|
IncompleteBody{},
|
|
|
|
ErrIncompleteBody,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectExistsAsDirectory{},
|
|
|
|
ErrObjectExistsAsDirectory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BucketNameInvalid{},
|
|
|
|
ErrInvalidBucketName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BucketExists{},
|
|
|
|
ErrBucketAlreadyOwnedByYou,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectNotFound{},
|
|
|
|
ErrNoSuchKey,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectNameInvalid{},
|
|
|
|
ErrInvalidObjectName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
InvalidUploadID{},
|
|
|
|
ErrNoSuchUpload,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
InvalidPart{},
|
|
|
|
ErrInvalidPart,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
InsufficientReadQuorum{},
|
|
|
|
ErrReadQuorum,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
InsufficientWriteQuorum{},
|
|
|
|
ErrWriteQuorum,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
UnsupportedDelimiter{},
|
|
|
|
ErrNotImplemented,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
InvalidMarkerPrefixCombination{},
|
|
|
|
ErrNotImplemented,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
InvalidUploadIDKeyCombination{},
|
|
|
|
ErrNotImplemented,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
MalformedUploadID{},
|
|
|
|
ErrNoSuchUpload,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PartTooSmall{},
|
|
|
|
ErrEntityTooSmall,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BucketNotEmpty{},
|
|
|
|
ErrBucketNotEmpty,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BucketNotFound{},
|
|
|
|
ErrNoSuchBucket,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
StorageFull{},
|
|
|
|
ErrStorageFull,
|
|
|
|
},
|
2017-03-16 15:21:58 -04:00
|
|
|
{
|
|
|
|
NotImplemented{},
|
|
|
|
ErrNotImplemented,
|
|
|
|
},
|
2016-09-15 04:44:19 -04:00
|
|
|
{
|
|
|
|
errSignatureMismatch,
|
|
|
|
ErrSignatureDoesNotMatch,
|
|
|
|
}, // End of all valid cases.
|
|
|
|
|
|
|
|
// Case where err is nil.
|
|
|
|
{
|
|
|
|
nil,
|
|
|
|
ErrNone,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Case where err type is unknown.
|
|
|
|
{
|
|
|
|
errors.New("Custom error"),
|
|
|
|
ErrInternalError,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate all the errors with their API error codes.
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
errCode := toAPIErrorCode(testCase.err)
|
|
|
|
if errCode != testCase.errCode {
|
|
|
|
t.Errorf("Test %d: Expected error code %d, got %d", i+1, testCase.errCode, errCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|