Adding tests for put bucket errors, fixed mismatching error
This commit is contained in:
parent
a6fc618f91
commit
db1e6e5988
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue