Merge pull request #436 from fkautz/pr_out_adding_tests_for_put_bucket_errors_fixed_mismatching_error

This commit is contained in:
Frederick F. Kautz IV 2015-04-03 18:38:05 -07:00
commit 407251d51f
2 changed files with 34 additions and 7 deletions

View file

@ -141,16 +141,11 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques
}
case drivers.BucketExists:
{
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
}
case drivers.ImplementationError:
{
log.Error.Println(err)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
writeErrorResponse(w, req, BucketAlreadyExists, acceptsContentType, req.URL.Path)
}
default:
{
log.Error.Println(err)
log.Error.Println(iodine.New(err, nil))
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
}

View file

@ -950,6 +950,38 @@ func (s *MySuite) TestListBucketsErrors(c *C) {
verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError)
}
func (s *MySuite) TestPutBucketHandler(c *C) {
driver := startMockDriver()
typedDriver := driver
defer driver.AssertExpectations(c)
httpHandler := api.HTTPHandler("", driver)
testServer := httptest.NewServer(httpHandler)
defer testServer.Close()
client := http.Client{}
typedDriver.On("CreateBucket", "foo").Return(drivers.BucketNameInvalid{}).Once()
request, err := http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
c.Assert(err, IsNil)
response, err := client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
typedDriver.On("CreateBucket", "foo").Return(drivers.BucketExists{}).Once()
request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict)
typedDriver.On("CreateBucket", "foo").Return(drivers.BackendCorrupted{}).Once()
request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
c.Assert(err, IsNil)
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError)
}
func verifyError(c *C, response *http.Response, code, description string, statusCode int) {
data, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)