You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
5.1 KiB
107 lines
5.1 KiB
9 years ago
|
/*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
9 years ago
|
// Wrapper for calling GetObjectInfo tests for both XL multiple disks and single node setup.
|
||
9 years ago
|
func TestGetObjectInfo(t *testing.T) {
|
||
9 years ago
|
ExecObjectLayerTest(t, testGetObjectInfo)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
// Testing GetObjectInfo().
|
||
9 years ago
|
func testGetObjectInfo(obj ObjectLayer, instanceType string, t TestErrHandler) {
|
||
9 years ago
|
// This bucket is used for testing getObjectInfo operations.
|
||
9 years ago
|
err := obj.MakeBucket("test-getobjectinfo")
|
||
9 years ago
|
if err != nil {
|
||
9 years ago
|
t.Fatalf("%s : %s", instanceType, err.Error())
|
||
9 years ago
|
}
|
||
|
_, err = obj.PutObject("test-getobjectinfo", "Asia/asiapics.jpg", int64(len("asiapics")), bytes.NewBufferString("asiapics"), nil)
|
||
|
if err != nil {
|
||
9 years ago
|
t.Fatalf("%s : %s", instanceType, err.Error())
|
||
9 years ago
|
}
|
||
|
resultCases := []ObjectInfo{
|
||
|
// ObjectInfo -1.
|
||
|
// ObjectName set to a existing object in the test case (Test case 14).
|
||
|
{Bucket: "test-getobjectinfo", Name: "Asia/asiapics.jpg", ContentType: "image/jpeg", IsDir: false},
|
||
|
}
|
||
|
testCases := []struct {
|
||
|
bucketName string
|
||
|
objectName string
|
||
|
|
||
|
// Expected output of GetObjectInfo.
|
||
|
result ObjectInfo
|
||
|
err error
|
||
|
// Flag indicating whether the test is expected to pass or not.
|
||
|
shouldPass bool
|
||
|
}{
|
||
|
// Test cases with invalid bucket names ( Test number 1-4 ).
|
||
|
{".test", "", ObjectInfo{}, BucketNameInvalid{Bucket: ".test"}, false},
|
||
|
{"Test", "", ObjectInfo{}, BucketNameInvalid{Bucket: "Test"}, false},
|
||
|
{"---", "", ObjectInfo{}, BucketNameInvalid{Bucket: "---"}, false},
|
||
|
{"ad", "", ObjectInfo{}, BucketNameInvalid{Bucket: "ad"}, false},
|
||
|
// Test cases with valid but non-existing bucket names (Test number 5-7).
|
||
|
{"abcdefgh", "abc", ObjectInfo{}, BucketNotFound{Bucket: "abcdefgh"}, false},
|
||
|
{"ijklmnop", "efg", ObjectInfo{}, BucketNotFound{Bucket: "ijklmnop"}, false},
|
||
|
// Test cases with valid but non-existing bucket names and invalid object name (Test number 8-9).
|
||
9 years ago
|
{"test-getobjectinfo", "", ObjectInfo{}, ObjectNameInvalid{Bucket: "test-getobjectinfo", Object: ""}, false},
|
||
|
{"test-getobjectinfo", "", ObjectInfo{}, ObjectNameInvalid{Bucket: "test-getobjectinfo", Object: ""}, false},
|
||
9 years ago
|
// Test cases with non-existing object name with existing bucket (Test number 10-12).
|
||
|
{"test-getobjectinfo", "Africa", ObjectInfo{}, ObjectNotFound{Bucket: "test-getobjectinfo", Object: "Africa"}, false},
|
||
|
{"test-getobjectinfo", "Antartica", ObjectInfo{}, ObjectNotFound{Bucket: "test-getobjectinfo", Object: "Antartica"}, false},
|
||
|
{"test-getobjectinfo", "Asia/myfile", ObjectInfo{}, ObjectNotFound{Bucket: "test-getobjectinfo", Object: "Asia/myfile"}, false},
|
||
|
// Test case with existing bucket but object name set to a directory (Test number 13).
|
||
|
{"test-getobjectinfo", "Asia", ObjectInfo{}, ObjectNotFound{Bucket: "test-getobjectinfo", Object: "Asia"}, false},
|
||
|
// Valid case with existing object (Test number 14).
|
||
|
{"test-getobjectinfo", "Asia/asiapics.jpg", resultCases[0], nil, true},
|
||
|
}
|
||
|
for i, testCase := range testCases {
|
||
|
result, err := obj.GetObjectInfo(testCase.bucketName, testCase.objectName)
|
||
|
if err != nil && testCase.shouldPass {
|
||
9 years ago
|
t.Errorf("Test %d: %s: Expected to pass, but failed with: <ERROR> %s", i+1, instanceType, err.Error())
|
||
9 years ago
|
}
|
||
|
if err == nil && !testCase.shouldPass {
|
||
9 years ago
|
t.Errorf("Test %d: %s: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, instanceType, testCase.err.Error())
|
||
9 years ago
|
}
|
||
|
// Failed as expected, but does it fail for the expected reason.
|
||
|
if err != nil && !testCase.shouldPass {
|
||
9 years ago
|
if testCase.err.Error() != err.Error() {
|
||
9 years ago
|
t.Errorf("Test %d: %s: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, instanceType, testCase.err.Error(), err.Error())
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// Test passes as expected, but the output values are verified for correctness here.
|
||
|
if err == nil && testCase.shouldPass {
|
||
|
if testCase.result.Bucket != result.Bucket {
|
||
9 years ago
|
t.Fatalf("Test %d: %s: Expected Bucket name to be '%s', but found '%s' instead", i+1, instanceType, testCase.result.Bucket, result.Bucket)
|
||
9 years ago
|
}
|
||
|
if testCase.result.Name != result.Name {
|
||
9 years ago
|
t.Errorf("Test %d: %s: Expected Object name to be %s, but instead found it to be %s", i+1, instanceType, testCase.result.Name, result.Name)
|
||
9 years ago
|
}
|
||
|
if testCase.result.ContentType != result.ContentType {
|
||
9 years ago
|
t.Errorf("Test %d: %s: Expected Content Type of the object to be %v, but instead found it to be %v", i+1, instanceType, testCase.result.ContentType, result.ContentType)
|
||
9 years ago
|
}
|
||
|
if testCase.result.IsDir != result.IsDir {
|
||
9 years ago
|
t.Errorf("Test %d: %s: Expected IsDir flag of the object to be %v, but instead found it to be %v", i+1, instanceType, testCase.result.IsDir, result.IsDir)
|
||
9 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|