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

Fixes #1488
This commit is contained in:
Harshavardhana 2016-05-05 01:35:21 -07:00 committed by Anand Babu (AB) Periasamy
parent f145e1042f
commit 82fbe908a3
3 changed files with 31 additions and 1 deletions

View File

@ -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
}

View File

@ -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]}

View File

@ -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)