2017-05-11 00:36:49 +02: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 "testing"
|
|
|
|
|
|
|
|
func TestToGCSPageToken(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
Name string
|
|
|
|
Token string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "A",
|
|
|
|
Token: "CgFB",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "AAAAAAAAAA",
|
|
|
|
Token: "CgpBQUFBQUFBQUFB",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
|
|
|
Token: "CmRBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-05-25 03:39:45 +02:00
|
|
|
|
|
|
|
// TestValidGCSProjectID tests the behavior of isValidGCSProjectID
|
|
|
|
func TestValidGCSProjectID(t *testing.T) {
|
|
|
|
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 {
|
|
|
|
if isValidGCSProjectID(testCase.ProjectID) != testCase.Valid {
|
|
|
|
t.Errorf("Test %d: Expected %v, got %v", i+1, isValidGCSProjectID(testCase.ProjectID), testCase.Valid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 08:13:53 +02:00
|
|
|
|
|
|
|
// Test for isGCSPrefix
|
|
|
|
func TestIsGCSPrefix(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
prefix string
|
|
|
|
expectedRes bool
|
|
|
|
}{
|
|
|
|
// Regular prefix without a trailing slash
|
|
|
|
{
|
|
|
|
prefix: "hello",
|
|
|
|
expectedRes: false,
|
|
|
|
},
|
|
|
|
// Regular prefix with a trailing slash
|
|
|
|
{
|
|
|
|
prefix: "hello/",
|
|
|
|
expectedRes: false,
|
|
|
|
},
|
|
|
|
// GCS prefix without a trailing slash
|
|
|
|
{
|
2017-06-18 01:00:41 +02:00
|
|
|
prefix: gcsMinioPath,
|
2017-06-06 08:13:53 +02:00
|
|
|
expectedRes: true,
|
|
|
|
},
|
|
|
|
// GCS prefix with a trailing slash
|
|
|
|
{
|
2017-06-18 01:00:41 +02:00
|
|
|
prefix: gcsMinioPath + "/",
|
2017-06-06 08:13:53 +02:00
|
|
|
expectedRes: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
|
|
|
if actualRes := isGCSPrefix(tc.prefix); actualRes != tc.expectedRes {
|
|
|
|
t.Errorf("%d: Expected isGCSPrefix to return %v but got %v", i, tc.expectedRes, actualRes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-10 04:48:20 +02:00
|
|
|
|
|
|
|
// Test for isGCSMarker.
|
|
|
|
func TestIsGCSMarker(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
marker string
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
marker: "##miniogcs123",
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
marker: "##mini_notgcs123",
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
marker: "#minioagainnotgcs123",
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-18 01:00:41 +02:00
|
|
|
|
|
|
|
// Test for gcsMultipartMetaName.
|
|
|
|
func TestGCSMultipartMetaName(t *testing.T) {
|
|
|
|
uploadID := "a"
|
2017-06-21 19:27:44 +02:00
|
|
|
expected := pathJoin(gcsMinioMultipartPathV1, uploadID, gcsMinioMultipartMeta)
|
2017-06-18 01:00:41 +02:00
|
|
|
got := gcsMultipartMetaName(uploadID)
|
|
|
|
if expected != got {
|
|
|
|
t.Errorf("expected: %s, got: %s", expected, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for gcsMultipartDataName.
|
|
|
|
func TestGCSMultipartDataName(t *testing.T) {
|
|
|
|
uploadID := "a"
|
|
|
|
etag := "b"
|
2017-06-21 19:27:44 +02:00
|
|
|
expected := pathJoin(gcsMinioMultipartPathV1, uploadID, etag)
|
2017-06-18 01:00:41 +02:00
|
|
|
got := gcsMultipartDataName(uploadID, etag)
|
|
|
|
if expected != got {
|
|
|
|
t.Errorf("expected: %s, got: %s", expected, got)
|
|
|
|
}
|
|
|
|
}
|