2017-10-13 12:56:16 +02: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-06 02:58:09 +01:00
|
|
|
package b2
|
2017-10-13 12:56:16 +02:00
|
|
|
|
|
|
|
import (
|
2017-11-28 03:29:22 +01:00
|
|
|
"fmt"
|
2017-10-13 12:56:16 +02:00
|
|
|
"testing"
|
2017-11-28 03:29:22 +01:00
|
|
|
|
|
|
|
b2 "github.com/minio/blazer/base"
|
2017-12-06 02:58:09 +01:00
|
|
|
|
|
|
|
minio "github.com/minio/minio/cmd"
|
2017-10-13 12:56:16 +02:00
|
|
|
)
|
|
|
|
|
2017-11-28 03:29:22 +01:00
|
|
|
// Test b2 object error.
|
|
|
|
func TestB2ObjectError(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
params []string
|
|
|
|
b2Err error
|
|
|
|
expectedErr error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
[]string{}, nil, nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]string{}, fmt.Errorf("Not *Error"), fmt.Errorf("Not *Error"),
|
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{}, fmt.Errorf("Non B2 Error"), fmt.Errorf("Non B2 Error"),
|
2017-11-28 03:29:22 +01:00
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{"bucket"}, b2.Error{
|
2017-11-28 03:29:22 +01:00
|
|
|
StatusCode: 1,
|
|
|
|
Code: "duplicate_bucket_name",
|
2018-04-06 00:04:40 +02:00
|
|
|
}, minio.BucketAlreadyOwnedByYou{
|
2017-12-06 02:58:09 +01:00
|
|
|
Bucket: "bucket",
|
|
|
|
},
|
2017-11-28 03:29:22 +01:00
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{"bucket"}, b2.Error{
|
2017-11-28 03:29:22 +01:00
|
|
|
StatusCode: 1,
|
|
|
|
Code: "bad_request",
|
2018-04-06 00:04:40 +02:00
|
|
|
}, minio.BucketNotFound{
|
2017-12-06 02:58:09 +01:00
|
|
|
Bucket: "bucket",
|
|
|
|
},
|
2017-11-28 03:29:22 +01:00
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{"bucket", "object"}, b2.Error{
|
2017-11-28 03:29:22 +01:00
|
|
|
StatusCode: 1,
|
|
|
|
Code: "bad_request",
|
2018-04-06 00:04:40 +02:00
|
|
|
}, minio.ObjectNameInvalid{
|
2017-11-28 03:29:22 +01:00
|
|
|
Bucket: "bucket",
|
|
|
|
Object: "object",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{"bucket"}, b2.Error{
|
2017-11-28 03:29:22 +01:00
|
|
|
StatusCode: 1,
|
|
|
|
Code: "bad_bucket_id",
|
2018-04-06 00:04:40 +02:00
|
|
|
}, minio.BucketNotFound{Bucket: "bucket"},
|
2017-11-28 03:29:22 +01:00
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{"bucket", "object"}, b2.Error{
|
2017-11-28 03:29:22 +01:00
|
|
|
StatusCode: 1,
|
|
|
|
Code: "file_not_present",
|
2018-04-06 00:04:40 +02:00
|
|
|
}, minio.ObjectNotFound{
|
2017-11-28 03:29:22 +01:00
|
|
|
Bucket: "bucket",
|
|
|
|
Object: "object",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{"bucket", "object"}, b2.Error{
|
2017-11-28 03:29:22 +01:00
|
|
|
StatusCode: 1,
|
|
|
|
Code: "not_found",
|
2018-04-06 00:04:40 +02:00
|
|
|
}, minio.ObjectNotFound{
|
2017-11-28 03:29:22 +01:00
|
|
|
Bucket: "bucket",
|
|
|
|
Object: "object",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{"bucket"}, b2.Error{
|
2017-11-28 03:29:22 +01:00
|
|
|
StatusCode: 1,
|
|
|
|
Code: "cannot_delete_non_empty_bucket",
|
2018-04-06 00:04:40 +02:00
|
|
|
}, minio.BucketNotEmpty{
|
2017-12-06 02:58:09 +01:00
|
|
|
Bucket: "bucket",
|
|
|
|
},
|
2017-11-28 03:29:22 +01:00
|
|
|
},
|
|
|
|
{
|
2018-04-06 00:04:40 +02:00
|
|
|
[]string{"bucket", "object", "uploadID"}, b2.Error{
|
2017-11-28 03:29:22 +01:00
|
|
|
StatusCode: 1,
|
|
|
|
Message: "No active upload for",
|
2018-04-06 00:04:40 +02:00
|
|
|
}, minio.InvalidUploadID{
|
2017-11-28 03:29:22 +01:00
|
|
|
UploadID: "uploadID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
actualErr := b2ToObjectError(testCase.b2Err, testCase.params...)
|
|
|
|
if actualErr != nil {
|
|
|
|
if actualErr.Error() != testCase.expectedErr.Error() {
|
|
|
|
t.Errorf("Test %d: Expected %s, got %s", i+1, testCase.expectedErr, actualErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|