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/>.
|
2017-09-25 17:47:58 -04:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-04-14 20:52:38 -04:00
|
|
|
"context"
|
2017-09-25 17:47:58 -04:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Tests for if parent directory is object
|
2020-06-12 23:04:01 -04:00
|
|
|
func TestErasureParentDirIsObject(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-01-18 15:25:22 -05:00
|
|
|
obj, fsDisks, err := prepareErasureSets32(ctx)
|
2017-09-25 17:47:58 -04:00
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
t.Fatalf("Unable to initialize 'Erasure' object layer.")
|
2017-09-25 17:47:58 -04:00
|
|
|
}
|
2020-09-10 12:18:19 -04:00
|
|
|
defer obj.Shutdown(context.Background())
|
2017-09-25 17:47:58 -04:00
|
|
|
|
|
|
|
// Remove all disks.
|
|
|
|
for _, disk := range fsDisks {
|
|
|
|
defer os.RemoveAll(disk)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucketName := "testbucket"
|
|
|
|
objectName := "object"
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if err = obj.MakeBucketWithLocation(GlobalContext, bucketName, BucketOptions{}); err != nil {
|
2017-09-25 17:47:58 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-01-18 15:25:22 -05:00
|
|
|
|
2017-09-25 17:47:58 -04:00
|
|
|
objectContent := "12345"
|
2021-01-18 15:25:22 -05:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucketName, objectName,
|
2019-02-09 00:31:06 -05:00
|
|
|
mustGetPutObjReader(t, bytes.NewReader([]byte(objectContent)), int64(len(objectContent)), "", ""), ObjectOptions{})
|
2017-09-25 17:47:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
2021-01-18 15:25:22 -05:00
|
|
|
expectedErr bool
|
|
|
|
objectName string
|
2017-09-25 17:47:58 -04:00
|
|
|
}{
|
|
|
|
{
|
2021-01-18 15:25:22 -05:00
|
|
|
expectedErr: true,
|
|
|
|
objectName: pathJoin(objectName, "parent-is-object"),
|
2017-09-25 17:47:58 -04:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 15:25:22 -05:00
|
|
|
expectedErr: false,
|
|
|
|
objectName: pathJoin("no-parent", "object"),
|
2017-09-25 17:47:58 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-01-18 15:25:22 -05:00
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
_, err = obj.PutObject(GlobalContext, bucketName, testCase.objectName,
|
|
|
|
mustGetPutObjReader(t, bytes.NewReader([]byte(objectContent)), int64(len(objectContent)), "", ""), ObjectOptions{})
|
|
|
|
if testCase.expectedErr && err == nil {
|
|
|
|
t.Error("Expected error but got nil")
|
|
|
|
}
|
|
|
|
if !testCase.expectedErr && err != nil {
|
|
|
|
t.Errorf("Expected nil but got %v", err)
|
|
|
|
}
|
|
|
|
})
|
2017-09-25 17:47:58 -04:00
|
|
|
}
|
|
|
|
}
|