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