2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-06-06 04:51:56 -04:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-12-09 20:52:53 -05:00
|
|
|
"bytes"
|
2020-09-04 12:45:06 -04:00
|
|
|
"context"
|
2018-06-06 04:51:56 -04:00
|
|
|
"net/http/httptest"
|
|
|
|
"reflect"
|
2021-12-09 11:38:46 -05:00
|
|
|
"runtime"
|
2018-06-06 04:51:56 -04:00
|
|
|
"testing"
|
|
|
|
|
2023-01-23 06:12:47 -05:00
|
|
|
"github.com/minio/mux"
|
2021-06-14 17:54:37 -04:00
|
|
|
xnet "github.com/minio/pkg/net"
|
2018-06-06 04:51:56 -04:00
|
|
|
)
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
// Storage REST server, storageRESTReceiver and StorageRESTClient are
|
2018-06-06 04:51:56 -04:00
|
|
|
// inter-dependent, below test functions are sufficient to test all of them.
|
|
|
|
func testStorageAPIDiskInfo(t *testing.T, storage StorageAPI) {
|
|
|
|
testCases := []struct {
|
|
|
|
expectErr bool
|
|
|
|
}{
|
2020-07-13 12:51:07 -04:00
|
|
|
{true},
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2020-09-04 12:45:06 -04:00
|
|
|
_, err := storage.DiskInfo(context.Background())
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
2020-07-13 12:51:07 -04:00
|
|
|
if err != errUnformattedDisk {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, errUnformattedDisk, err)
|
|
|
|
}
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIMakeVol(t *testing.T, storage StorageAPI) {
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", false},
|
|
|
|
// volume exists error.
|
|
|
|
{"foo", true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), testCase.volumeName)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIListVols(t *testing.T, storage StorageAPI) {
|
|
|
|
testCases := []struct {
|
|
|
|
volumeNames []string
|
|
|
|
expectedResult []VolInfo
|
|
|
|
expectErr bool
|
|
|
|
}{
|
2021-01-22 18:38:21 -05:00
|
|
|
{nil, []VolInfo{{Name: ".minio.sys"}}, false},
|
|
|
|
{[]string{"foo"}, []VolInfo{{Name: ".minio.sys"}, {Name: "foo"}}, false},
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
for _, volumeName := range testCase.volumeNames {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), volumeName)
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
result, err := storage.ListVols(context.Background())
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !testCase.expectErr {
|
|
|
|
if len(result) != len(testCase.expectedResult) {
|
|
|
|
t.Fatalf("case %v: result: expected: %+v, got: %+v", i+1, testCase.expectedResult, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIStatVol(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", false},
|
|
|
|
// volume not found error.
|
|
|
|
{"bar", true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2020-09-04 12:45:06 -04:00
|
|
|
result, err := storage.StatVol(context.Background(), testCase.volumeName)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !testCase.expectErr {
|
|
|
|
if result.Name != testCase.volumeName {
|
|
|
|
t.Fatalf("case %v: result: expected: %+v, got: %+v", i+1, testCase.volumeName, result.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIDeleteVol(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", false},
|
|
|
|
// volume not found error.
|
|
|
|
{"bar", true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.DeleteVol(context.Background(), testCase.volumeName, false)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:26:57 -04:00
|
|
|
func testStorageAPIStatInfoFile(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
err = storage.AppendFile(context.Background(), "foo", pathJoin("myobject", xlStorageFormatFile), []byte("foo"))
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
objectName string
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", "myobject", false},
|
|
|
|
// file not found error.
|
|
|
|
{"foo", "yourobject", true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2021-10-01 14:50:00 -04:00
|
|
|
_, err := storage.StatInfoFile(context.Background(), testCase.volumeName, testCase.objectName+"/"+xlStorageFormatFile, false)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
2021-10-01 14:50:00 -04:00
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v, err: %v", i+1, expectErr, testCase.expectErr, err)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIListDir(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
err = storage.AppendFile(context.Background(), "foo", "path/to/myobject", []byte("foo"))
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
prefix string
|
|
|
|
expectedResult []string
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", "path", []string{"to/"}, false},
|
|
|
|
// prefix not found error.
|
|
|
|
{"foo", "nodir", nil, true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2020-09-04 12:45:06 -04:00
|
|
|
result, err := storage.ListDir(context.Background(), testCase.volumeName, testCase.prefix, -1)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !testCase.expectErr {
|
|
|
|
if !reflect.DeepEqual(result, testCase.expectedResult) {
|
|
|
|
t.Fatalf("case %v: result: expected: %v, got: %v", i+1, testCase.expectedResult, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIReadAll(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
err = storage.AppendFile(context.Background(), "foo", "myobject", []byte("foo"))
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
objectName string
|
|
|
|
expectedResult []byte
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", "myobject", []byte("foo"), false},
|
|
|
|
// file not found error.
|
|
|
|
{"foo", "yourobject", nil, true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2020-09-04 12:45:06 -04:00
|
|
|
result, err := storage.ReadAll(context.Background(), testCase.volumeName, testCase.objectName)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !testCase.expectErr {
|
|
|
|
if !reflect.DeepEqual(result, testCase.expectedResult) {
|
|
|
|
t.Fatalf("case %v: result: expected: %v, got: %v", i+1, string(testCase.expectedResult), string(result))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIReadFile(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
err = storage.AppendFile(context.Background(), "foo", "myobject", []byte("foo"))
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
objectName string
|
|
|
|
offset int64
|
|
|
|
expectedResult []byte
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", "myobject", 0, []byte("foo"), false},
|
|
|
|
{"foo", "myobject", 1, []byte("oo"), false},
|
|
|
|
// file not found error.
|
|
|
|
{"foo", "yourobject", 0, nil, true},
|
|
|
|
}
|
|
|
|
|
2018-08-06 18:14:08 -04:00
|
|
|
result := make([]byte, 100)
|
2018-06-06 04:51:56 -04:00
|
|
|
for i, testCase := range testCases {
|
2018-08-06 18:14:08 -04:00
|
|
|
result = result[testCase.offset:3]
|
2020-09-04 12:45:06 -04:00
|
|
|
_, err := storage.ReadFile(context.Background(), testCase.volumeName, testCase.objectName, testCase.offset, result, nil)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !testCase.expectErr {
|
|
|
|
if !reflect.DeepEqual(result, testCase.expectedResult) {
|
|
|
|
t.Fatalf("case %v: result: expected: %v, got: %v", i+1, string(testCase.expectedResult), string(result))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIAppendFile(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
2021-12-09 20:52:53 -05:00
|
|
|
testData := []byte("foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
testCases := []struct {
|
2021-12-09 11:38:46 -05:00
|
|
|
volumeName string
|
|
|
|
objectName string
|
|
|
|
data []byte
|
|
|
|
expectErr bool
|
|
|
|
ignoreIfWindows bool
|
2018-06-06 04:51:56 -04:00
|
|
|
}{
|
2021-12-09 20:52:53 -05:00
|
|
|
{"foo", "myobject", testData, false, false},
|
|
|
|
{"foo", "myobject-0byte", []byte{}, false, false},
|
2018-06-06 04:51:56 -04:00
|
|
|
// volume not found error.
|
2021-12-09 20:52:53 -05:00
|
|
|
{"bar", "myobject", testData, true, false},
|
|
|
|
// Test some weird characters over the wire.
|
|
|
|
{"foo", "newline\n", testData, false, true},
|
|
|
|
{"foo", "newline\t", testData, false, true},
|
|
|
|
{"foo", "newline \n", testData, false, true},
|
|
|
|
{"foo", "newline$$$\n", testData, false, true},
|
|
|
|
{"foo", "newline%%%\n", testData, false, true},
|
|
|
|
{"foo", "newline \t % $ & * ^ # @ \n", testData, false, true},
|
|
|
|
{"foo", "\n\tnewline \t % $ & * ^ # @ \n", testData, false, true},
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2021-12-09 11:38:46 -05:00
|
|
|
if testCase.ignoreIfWindows && runtime.GOOS == "windows" {
|
|
|
|
continue
|
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.AppendFile(context.Background(), testCase.volumeName, testCase.objectName, testCase.data)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
2021-12-09 20:52:53 -05:00
|
|
|
|
|
|
|
if !testCase.expectErr {
|
|
|
|
data, err := storage.ReadAll(context.Background(), testCase.volumeName, testCase.objectName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(data, testCase.data) {
|
|
|
|
t.Fatalf("case %v: expected %v, got %v", i+1, testCase.data, data)
|
|
|
|
}
|
|
|
|
}
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIDeleteFile(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
err = storage.AppendFile(context.Background(), "foo", "myobject", []byte("foo"))
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
objectName string
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", "myobject", false},
|
2021-06-07 12:35:08 -04:00
|
|
|
// file not found not returned
|
|
|
|
{"foo", "myobject", false},
|
|
|
|
// file not found not returned
|
|
|
|
{"foo", "yourobject", false},
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2022-07-11 12:15:54 -04:00
|
|
|
err := storage.Delete(context.Background(), testCase.volumeName, testCase.objectName, DeleteOptions{
|
|
|
|
Recursive: false,
|
|
|
|
Force: false,
|
|
|
|
})
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorageAPIRenameFile(t *testing.T, storage StorageAPI) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.MakeVol(context.Background(), "foo")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
err = storage.MakeVol(context.Background(), "bar")
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
err = storage.AppendFile(context.Background(), "foo", "myobject", []byte("foo"))
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
err = storage.AppendFile(context.Background(), "foo", "otherobject", []byte("foo"))
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
volumeName string
|
|
|
|
objectName string
|
|
|
|
destVolumeName string
|
|
|
|
destObjectName string
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{"foo", "myobject", "foo", "yourobject", false},
|
|
|
|
{"foo", "yourobject", "bar", "myobject", false},
|
|
|
|
// overwrite.
|
|
|
|
{"foo", "otherobject", "bar", "myobject", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2020-09-04 12:45:06 -04:00
|
|
|
err := storage.RenameFile(context.Background(), testCase.volumeName, testCase.objectName, testCase.destVolumeName, testCase.destObjectName)
|
2018-06-06 04:51:56 -04:00
|
|
|
expectErr := (err != nil)
|
|
|
|
|
|
|
|
if expectErr != testCase.expectErr {
|
|
|
|
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 15:37:26 -04:00
|
|
|
func newStorageRESTHTTPServerClient(t *testing.T) *storageRESTClient {
|
2019-11-26 14:42:10 -05:00
|
|
|
prevHost, prevPort := globalMinioHost, globalMinioPort
|
|
|
|
defer func() {
|
|
|
|
globalMinioHost, globalMinioPort = prevHost, prevPort
|
|
|
|
}()
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
router := mux.NewRouter()
|
|
|
|
httpServer := httptest.NewServer(router)
|
2022-07-25 15:37:26 -04:00
|
|
|
t.Cleanup(httpServer.Close)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2019-10-31 02:39:09 -04:00
|
|
|
url, err := xnet.ParseHTTPURL(httpServer.URL)
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
2022-07-25 15:37:26 -04:00
|
|
|
url.Path = t.TempDir()
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2019-11-26 14:42:10 -05:00
|
|
|
globalMinioHost, globalMinioPort = mustSplitHostPort(url.Host)
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
endpoint, err := NewEndpoint(url.String())
|
2018-06-06 04:51:56 -04:00
|
|
|
if err != nil {
|
2018-10-04 20:44:06 -04:00
|
|
|
t.Fatalf("NewEndpoint failed %v", endpoint)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2019-11-26 14:42:10 -05:00
|
|
|
if err = endpoint.UpdateIsLocal(); err != nil {
|
2019-04-19 13:26:44 -04:00
|
|
|
t.Fatalf("UpdateIsLocal failed %v", err)
|
|
|
|
}
|
|
|
|
|
2021-01-26 23:47:42 -05:00
|
|
|
registerStorageRESTHandlers(router, []PoolEndpoints{{
|
2019-11-19 20:42:27 -05:00
|
|
|
Endpoints: Endpoints{endpoint},
|
|
|
|
}})
|
2019-11-26 14:42:10 -05:00
|
|
|
|
2020-10-26 13:29:29 -04:00
|
|
|
restClient := newStorageRESTClient(endpoint, false)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2022-07-25 15:37:26 -04:00
|
|
|
return restClient
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientDiskInfo(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIDiskInfo(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientMakeVol(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIMakeVol(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientListVols(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIListVols(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientStatVol(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIStatVol(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientDeleteVol(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIDeleteVol(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-03 16:26:57 -04:00
|
|
|
func TestStorageRESTClientStatInfoFile(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2021-08-03 16:26:57 -04:00
|
|
|
testStorageAPIStatInfoFile(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientListDir(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIListDir(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientReadAll(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIReadAll(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientReadFile(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIReadFile(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientAppendFile(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIAppendFile(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientDeleteFile(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIDeleteFile(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
func TestStorageRESTClientRenameFile(t *testing.T) {
|
2022-07-25 15:37:26 -04:00
|
|
|
restClient := newStorageRESTHTTPServerClient(t)
|
2018-06-06 04:51:56 -04:00
|
|
|
|
2018-10-04 20:44:06 -04:00
|
|
|
testStorageAPIRenameFile(t, restClient)
|
2018-06-06 04:51:56 -04:00
|
|
|
}
|