Support creating empty directories. (#5049)

Every so often we get requirements for creating
directories/prefixes and we end up rejecting
such requirements. This PR implements this and
allows empty directories without any new file
addition to backend.

Existing lower APIs themselves are leveraged to provide
this behavior. Only FS backend supports this for
the time being as desired.
This commit is contained in:
Harshavardhana
2017-10-16 17:20:54 -07:00
committed by Dee Koder
parent 0c0d1e4150
commit b2cbade477
6 changed files with 186 additions and 80 deletions

View File

@@ -27,6 +27,7 @@ import (
"math/rand"
"net/http"
"net/url"
"os"
"reflect"
"strings"
"sync"
@@ -43,6 +44,7 @@ type TestSuiteCommon struct {
endPoint string
accessKey string
secretKey string
configPath string
signer signerType
secure bool
transport *http.Transport
@@ -56,7 +58,7 @@ type check struct {
// Assert - checks if gotValue is same as expectedValue, if not fails the test.
func (c *check) Assert(gotValue interface{}, expectedValue interface{}) {
if !reflect.DeepEqual(gotValue, expectedValue) {
c.Fatalf("Test %s: expected %v, got %v", c.testType, expectedValue, gotValue)
c.Fatalf("Test %s:%s expected %v, got %v", getSource(), c.testType, expectedValue, gotValue)
}
}
@@ -74,7 +76,9 @@ func verifyError(c *check, response *http.Response, code, description string, st
func runAllTests(suite *TestSuiteCommon, c *check) {
suite.SetUpSuite(c)
suite.TestBucketSQSNotificationWebHook(c)
suite.TestObjectDir(c)
if suite.serverType == "XL" {
suite.TestObjectDir(c)
}
suite.TestBucketSQSNotificationAMQP(c)
suite.TestBucketPolicy(c)
suite.TestDeleteBucket(c)
@@ -140,6 +144,9 @@ func TestServerSuite(t *testing.T) {
// Setting up the test suite.
// Starting the Test server with temporary FS backend.
func (s *TestSuiteCommon) SetUpSuite(c *check) {
rootPath, err := newTestConfig("us-east-1")
c.Assert(err, nil)
if s.secure {
cert, key, err := generateTLSCertKey("127.0.0.1")
c.Assert(err, nil)
@@ -163,10 +170,12 @@ func (s *TestSuiteCommon) SetUpSuite(c *check) {
s.endPoint = s.testServer.Server.URL
s.accessKey = s.testServer.AccessKey
s.secretKey = s.testServer.SecretKey
s.configPath = rootPath
}
// Called implicitly by "gopkg.in/check.v1" after all tests are run.
func (s *TestSuiteCommon) TearDownSuite(c *check) {
os.RemoveAll(s.configPath)
s.testServer.Stop()
}