mirror of https://github.com/minio/minio.git
Merge pull request #437 from fkautz/pr_out_better_error_handling_tests_for_get_object
This commit is contained in:
commit
321a1a2d36
|
@ -61,9 +61,8 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
||||||
w.WriteHeader(http.StatusPartialContent)
|
w.WriteHeader(http.StatusPartialContent)
|
||||||
_, err := server.driver.GetPartialObject(w, bucket, object, httpRange.start, httpRange.length)
|
_, err := server.driver.GetPartialObject(w, bucket, object, httpRange.start, httpRange.length)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = iodine.New(err, nil)
|
|
||||||
// unable to write headers, we've already printed data. Just close the connection.
|
// unable to write headers, we've already printed data. Just close the connection.
|
||||||
log.Error.Println(err)
|
log.Error.Println(iodine.New(err, nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,14 +83,9 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
||||||
{
|
{
|
||||||
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.ImplementationError:
|
|
||||||
{
|
|
||||||
log.Error.Println(err)
|
|
||||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log.Error.Println(err)
|
log.Error.Println(iodine.New(err, nil))
|
||||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -894,9 +894,18 @@ func (s *MySuite) TestPartialContent(c *C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestListObjectsHandlerErrors(c *C) {
|
func (s *MySuite) TestListObjectsHandlerErrors(c *C) {
|
||||||
driver := startMockDriver()
|
switch driver := s.Driver.(type) {
|
||||||
typedDriver := driver
|
case *mocks.Driver:
|
||||||
defer driver.AssertExpectations(c)
|
{
|
||||||
|
driver.AssertExpectations(c)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
driver := s.Driver
|
||||||
|
typedDriver := s.MockDriver
|
||||||
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
|
@ -933,9 +942,18 @@ func (s *MySuite) TestListObjectsHandlerErrors(c *C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestListBucketsErrors(c *C) {
|
func (s *MySuite) TestListBucketsErrors(c *C) {
|
||||||
driver := startMockDriver()
|
switch driver := s.Driver.(type) {
|
||||||
typedDriver := driver
|
case *mocks.Driver:
|
||||||
defer driver.AssertExpectations(c)
|
{
|
||||||
|
driver.AssertExpectations(c)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
driver := s.Driver
|
||||||
|
typedDriver := s.MockDriver
|
||||||
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
|
@ -950,10 +968,19 @@ func (s *MySuite) TestListBucketsErrors(c *C) {
|
||||||
verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError)
|
verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestPutBucketHandler(c *C) {
|
func (s *MySuite) TestPutBucketErrors(c *C) {
|
||||||
driver := startMockDriver()
|
switch driver := s.Driver.(type) {
|
||||||
typedDriver := driver
|
case *mocks.Driver:
|
||||||
defer driver.AssertExpectations(c)
|
{
|
||||||
|
driver.AssertExpectations(c)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
driver := s.Driver
|
||||||
|
typedDriver := s.MockDriver
|
||||||
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
|
@ -982,6 +1009,61 @@ func (s *MySuite) TestPutBucketHandler(c *C) {
|
||||||
verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError)
|
verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MySuite) TestGetObjectErrors(c *C) {
|
||||||
|
switch driver := s.Driver.(type) {
|
||||||
|
case *mocks.Driver:
|
||||||
|
{
|
||||||
|
driver.AssertExpectations(c)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
driver := s.Driver
|
||||||
|
typedDriver := s.MockDriver
|
||||||
|
|
||||||
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
|
testServer := httptest.NewServer(httpHandler)
|
||||||
|
defer testServer.Close()
|
||||||
|
client := http.Client{}
|
||||||
|
|
||||||
|
typedDriver.On("GetObjectMetadata", "foo", "bar", "").Return(drivers.ObjectMetadata{}, drivers.ObjectNotFound{}).Once()
|
||||||
|
request, err := http.NewRequest("GET", testServer.URL+"/foo/bar", bytes.NewBufferString(""))
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
response, err := client.Do(request)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
|
||||||
|
|
||||||
|
typedDriver.On("GetObjectMetadata", "foo", "bar", "").Return(drivers.ObjectMetadata{}, drivers.BucketNotFound{}).Once()
|
||||||
|
request, err = http.NewRequest("GET", testServer.URL+"/foo/bar", bytes.NewBufferString(""))
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
response, err = client.Do(request)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
verifyError(c, response, "NoSuchBucket", "The specified bucket does not exist.", http.StatusNotFound)
|
||||||
|
|
||||||
|
typedDriver.On("GetObjectMetadata", "foo", "bar", "").Return(drivers.ObjectMetadata{}, drivers.ObjectNameInvalid{}).Once()
|
||||||
|
request, err = http.NewRequest("GET", testServer.URL+"/foo/bar", bytes.NewBufferString(""))
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
response, err = client.Do(request)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
verifyError(c, response, "NoSuchKey", "The specified key does not exist.", http.StatusNotFound)
|
||||||
|
|
||||||
|
typedDriver.On("GetObjectMetadata", "foo", "bar", "").Return(drivers.ObjectMetadata{}, drivers.BucketNameInvalid{}).Once()
|
||||||
|
request, err = http.NewRequest("GET", testServer.URL+"/foo/bar", 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("GetObjectMetadata", "foo", "bar", "").Return(drivers.ObjectMetadata{}, drivers.BackendCorrupted{}).Once()
|
||||||
|
request, err = http.NewRequest("GET", testServer.URL+"/foo/bar", 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) {
|
func verifyError(c *C, response *http.Response, code, description string, statusCode int) {
|
||||||
data, err := ioutil.ReadAll(response.Body)
|
data, err := ioutil.ReadAll(response.Body)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
Loading…
Reference in New Issue