object: DeleteBucket should return proper error for BucketNotEmpty. (#1489)

Fixes #1488
master
Harshavardhana 9 years ago committed by Anand Babu (AB) Periasamy
parent f145e1042f
commit 82fbe908a3
  1. 2
      object-common.go
  2. 4
      object-errors.go
  3. 26
      server_test.go

@ -96,7 +96,7 @@ func deleteBucket(storage StorageAPI, bucket string) error {
return BucketNameInvalid{Bucket: bucket}
}
if err := storage.DeleteVol(bucket); err != nil {
return toObjectErr(err)
return toObjectErr(err, bucket)
}
return nil
}

@ -30,6 +30,10 @@ func toObjectErr(err error, params ...string) error {
if len(params) >= 1 {
return BucketNotFound{Bucket: params[0]}
}
case errVolumeNotEmpty:
if len(params) >= 1 {
return BucketNotEmpty{Bucket: params[0]}
}
case errVolumeExists:
if len(params) >= 1 {
return BucketExists{Bucket: params[0]}

@ -379,6 +379,32 @@ func (s *MyAPISuite) TestDeleteBucket(c *C) {
c.Assert(response.StatusCode, Equals, http.StatusNoContent)
}
func (s *MyAPISuite) TestDeleteBucketNotEmpty(c *C) {
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/deletebucket-notempty", 0, nil)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/deletebucket-notempty/myobject", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = s.newRequest("DELETE", testAPIFSCacheServer.URL+"/deletebucket-notempty", 0, nil)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusConflict)
}
func (s *MyAPISuite) TestDeleteObject(c *C) {
request, err := s.newRequest("PUT", testAPIFSCacheServer.URL+"/deletebucketobject", 0, nil)
c.Assert(err, IsNil)

Loading…
Cancel
Save