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.
397 lines
13 KiB
397 lines
13 KiB
8 years ago
|
/*
|
||
7 years ago
|
* Minio Cloud Storage, (C) 2017 Minio, Inc.
|
||
8 years ago
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
7 years ago
|
package gcs
|
||
8 years ago
|
|
||
8 years ago
|
import (
|
||
8 years ago
|
"fmt"
|
||
7 years ago
|
"io/ioutil"
|
||
|
"os"
|
||
7 years ago
|
"path"
|
||
8 years ago
|
"reflect"
|
||
|
"testing"
|
||
|
|
||
7 years ago
|
"github.com/minio/minio/pkg/errors"
|
||
|
"google.golang.org/api/googleapi"
|
||
7 years ago
|
|
||
|
miniogo "github.com/minio/minio-go"
|
||
|
minio "github.com/minio/minio/cmd"
|
||
8 years ago
|
)
|
||
8 years ago
|
|
||
|
func TestToGCSPageToken(t *testing.T) {
|
||
|
testCases := []struct {
|
||
|
Name string
|
||
|
Token string
|
||
|
}{
|
||
|
{
|
||
|
Name: "A",
|
||
|
Token: "CgFB",
|
||
|
},
|
||
|
{
|
||
|
Name: "AAAAAAAAAA",
|
||
|
Token: "CgpBQUFBQUFBQUFB",
|
||
|
},
|
||
|
{
|
||
|
Name: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
||
|
Token: "CmRBQUFBQUFBQUFBQUFBQ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BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUE=",
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for i, testCase := range testCases {
|
||
|
if toGCSPageToken(testCase.Name) != testCase.Token {
|
||
|
t.Errorf("Test %d: Expected %s, got %s", i+1, toGCSPageToken(testCase.Name), testCase.Token)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
// TestIsValidGCSProjectIDFormat tests isValidGCSProjectIDFormat
|
||
|
func TestValidGCSProjectIDFormat(t *testing.T) {
|
||
8 years ago
|
testCases := []struct {
|
||
|
ProjectID string
|
||
|
Valid bool
|
||
|
}{
|
||
|
{"", false},
|
||
|
{"a", false},
|
||
|
{"Abc", false},
|
||
|
{"1bcd", false},
|
||
|
// 5 chars
|
||
|
{"abcdb", false},
|
||
|
// 6 chars
|
||
|
{"abcdbz", true},
|
||
|
// 30 chars
|
||
|
{"project-id-1-project-id-more-1", true},
|
||
|
// 31 chars
|
||
|
{"project-id-1-project-id-more-11", false},
|
||
|
{"storage.googleapis.com", false},
|
||
|
{"http://storage.googleapis.com", false},
|
||
|
{"http://localhost:9000", false},
|
||
|
{"project-id-1", true},
|
||
|
{"project-id-1988832", true},
|
||
|
{"projectid1414", true},
|
||
|
}
|
||
|
|
||
|
for i, testCase := range testCases {
|
||
8 years ago
|
valid := isValidGCSProjectIDFormat(testCase.ProjectID)
|
||
|
if valid != testCase.Valid {
|
||
|
t.Errorf("Test %d: Expected %v, got %v", i+1, valid, testCase.Valid)
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
// Test for isGCSMarker.
|
||
|
func TestIsGCSMarker(t *testing.T) {
|
||
|
testCases := []struct {
|
||
|
marker string
|
||
|
expected bool
|
||
|
}{
|
||
|
{
|
||
8 years ago
|
marker: "{minio}gcs123",
|
||
8 years ago
|
expected: true,
|
||
|
},
|
||
|
{
|
||
8 years ago
|
marker: "{mini_no}tgcs123",
|
||
8 years ago
|
expected: false,
|
||
|
},
|
||
|
{
|
||
8 years ago
|
marker: "{minioagainnotgcs123",
|
||
8 years ago
|
expected: false,
|
||
|
},
|
||
|
{
|
||
|
marker: "obj1",
|
||
|
expected: false,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for i, tc := range testCases {
|
||
|
if actual := isGCSMarker(tc.marker); actual != tc.expected {
|
||
|
t.Errorf("Test %d: marker is %s, expected %v but got %v",
|
||
|
i+1, tc.marker, tc.expected, actual)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
|
// Test for gcsMultipartMetaName.
|
||
|
func TestGCSMultipartMetaName(t *testing.T) {
|
||
|
uploadID := "a"
|
||
7 years ago
|
expected := path.Join(gcsMinioMultipartPathV1, uploadID, gcsMinioMultipartMeta)
|
||
8 years ago
|
got := gcsMultipartMetaName(uploadID)
|
||
|
if expected != got {
|
||
|
t.Errorf("expected: %s, got: %s", expected, got)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Test for gcsMultipartDataName.
|
||
|
func TestGCSMultipartDataName(t *testing.T) {
|
||
8 years ago
|
var (
|
||
|
uploadID = "a"
|
||
|
etag = "b"
|
||
|
partNumber = 1
|
||
|
)
|
||
7 years ago
|
expected := path.Join(gcsMinioMultipartPathV1, uploadID, fmt.Sprintf("%05d.%s", partNumber, etag))
|
||
8 years ago
|
got := gcsMultipartDataName(uploadID, partNumber, etag)
|
||
8 years ago
|
if expected != got {
|
||
|
t.Errorf("expected: %s, got: %s", expected, got)
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
|
func TestFromMinioClientListBucketResultToV2Info(t *testing.T) {
|
||
|
|
||
7 years ago
|
listBucketResult := miniogo.ListBucketResult{
|
||
8 years ago
|
IsTruncated: false,
|
||
|
Marker: "testMarker",
|
||
|
NextMarker: "testMarker2",
|
||
7 years ago
|
CommonPrefixes: []miniogo.CommonPrefix{{Prefix: "one"}, {Prefix: "two"}},
|
||
|
Contents: []miniogo.ObjectInfo{{Key: "testobj", ContentType: ""}},
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
listBucketV2Info := minio.ListObjectsV2Info{
|
||
8 years ago
|
Prefixes: []string{"one", "two"},
|
||
7 years ago
|
Objects: []minio.ObjectInfo{{Name: "testobj", Bucket: "testbucket", UserDefined: map[string]string{"Content-Type": ""}}},
|
||
8 years ago
|
IsTruncated: false,
|
||
|
ContinuationToken: "testMarker",
|
||
|
NextContinuationToken: "testMarker2",
|
||
|
}
|
||
|
|
||
7 years ago
|
if got := minio.FromMinioClientListBucketResultToV2Info("testbucket", listBucketResult); !reflect.DeepEqual(got, listBucketV2Info) {
|
||
8 years ago
|
t.Errorf("fromMinioClientListBucketResultToV2Info() = %v, want %v", got, listBucketV2Info)
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
|
// Test for gcsParseProjectID
|
||
|
func TestGCSParseProjectID(t *testing.T) {
|
||
|
f, err := ioutil.TempFile("", "")
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
return
|
||
|
}
|
||
|
defer os.Remove(f.Name())
|
||
|
defer f.Close()
|
||
|
|
||
|
contents := `
|
||
|
{
|
||
|
"type": "service_account",
|
||
|
"project_id": "miniotesting"
|
||
|
}
|
||
|
`
|
||
|
f.WriteString(contents)
|
||
|
projectID, err := gcsParseProjectID(f.Name())
|
||
|
if err != nil {
|
||
7 years ago
|
t.Fatal(err)
|
||
7 years ago
|
}
|
||
|
if projectID != "miniotesting" {
|
||
|
t.Errorf(`Expected projectID value to be "miniotesting"`)
|
||
|
}
|
||
7 years ago
|
|
||
|
if _, err = gcsParseProjectID("non-existent"); err == nil {
|
||
|
t.Errorf(`Expected to fail but succeeded reading "non-existent"`)
|
||
|
}
|
||
|
|
||
|
f.WriteString(`,}`)
|
||
|
|
||
|
if _, err := gcsParseProjectID(f.Name()); err == nil {
|
||
|
t.Errorf(`Expected to fail reading corrupted credentials file`)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestGCSToObjectError(t *testing.T) {
|
||
|
testCases := []struct {
|
||
|
params []string
|
||
|
gcsErr error
|
||
|
expectedErr error
|
||
|
}{
|
||
|
{
|
||
|
[]string{}, nil, nil,
|
||
|
},
|
||
|
{
|
||
|
[]string{}, fmt.Errorf("Not *Error"), fmt.Errorf("Not *Error"),
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket"},
|
||
|
errors.Trace(fmt.Errorf("storage: bucket doesn't exist")),
|
||
7 years ago
|
minio.BucketNotFound{
|
||
7 years ago
|
Bucket: "bucket",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(fmt.Errorf("storage: object doesn't exist")),
|
||
7 years ago
|
minio.ObjectNotFound{
|
||
7 years ago
|
Bucket: "bucket",
|
||
|
Object: "object",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object", "uploadID"},
|
||
|
errors.Trace(fmt.Errorf("storage: object doesn't exist")),
|
||
7 years ago
|
minio.InvalidUploadID{
|
||
7 years ago
|
UploadID: "uploadID",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{},
|
||
|
errors.Trace(fmt.Errorf("Unknown error")),
|
||
|
fmt.Errorf("Unknown error"),
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Message: "No list of errors",
|
||
|
}),
|
||
|
&googleapi.Error{
|
||
|
Message: "No list of errors",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "conflict",
|
||
|
Message: "You already own this bucket. Please select another name.",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.BucketAlreadyOwnedByYou{
|
||
|
Bucket: "bucket",
|
||
|
},
|
||
7 years ago
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "conflict",
|
||
|
Message: "Sorry, that name is not available. Please try a different one.",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.BucketAlreadyExists{
|
||
|
Bucket: "bucket",
|
||
|
},
|
||
7 years ago
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "conflict",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.BucketNotEmpty{Bucket: "bucket"},
|
||
7 years ago
|
},
|
||
|
{
|
||
|
[]string{"bucket"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "notFound",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.BucketNotFound{
|
||
|
Bucket: "bucket",
|
||
|
},
|
||
7 years ago
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "notFound",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.ObjectNotFound{
|
||
7 years ago
|
Bucket: "bucket",
|
||
|
Object: "object",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "invalid",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.BucketNameInvalid{
|
||
7 years ago
|
Bucket: "bucket",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "forbidden",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.PrefixAccessDenied{
|
||
7 years ago
|
Bucket: "bucket",
|
||
|
Object: "object",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "keyInvalid",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.PrefixAccessDenied{
|
||
7 years ago
|
Bucket: "bucket",
|
||
|
Object: "object",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "required",
|
||
|
}},
|
||
|
}),
|
||
7 years ago
|
minio.PrefixAccessDenied{
|
||
7 years ago
|
Bucket: "bucket",
|
||
|
Object: "object",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
[]string{"bucket", "object"},
|
||
|
errors.Trace(&googleapi.Error{
|
||
|
Errors: []googleapi.ErrorItem{{
|
||
|
Reason: "unknown",
|
||
|
}},
|
||
|
}),
|
||
|
fmt.Errorf("Unsupported error reason: unknown"),
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for i, testCase := range testCases {
|
||
|
actualErr := gcsToObjectError(testCase.gcsErr, testCase.params...)
|
||
|
if actualErr != nil {
|
||
|
if actualErr.Error() != testCase.expectedErr.Error() {
|
||
|
t.Errorf("Test %d: Expected %s, got %s", i+1, testCase.expectedErr, actualErr)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
7 years ago
|
}
|