mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
Implement headBucketHandler() and its related tests
Remove internal testify/mock and use upstream - update all godeps
This commit is contained in:
@@ -150,3 +150,39 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HEAD Bucket
|
||||
// ----------
|
||||
// This operation is useful to determine if a bucket exists.
|
||||
// The operation returns a 200 OK if the bucket exists and you
|
||||
// have permission to access it. Otherwise, the operation might
|
||||
// return responses such as 404 Not Found and 403 Forbidden.
|
||||
func (server *minioAPI) headBucketHandler(w http.ResponseWriter, req *http.Request) {
|
||||
// TODO need to peek into bucketPolicy return appropriate checks here
|
||||
vars := mux.Vars(req)
|
||||
bucket := vars["bucket"]
|
||||
acceptsContentType := getContentType(req)
|
||||
|
||||
_, err := server.driver.GetBucketMetadata(bucket)
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
{
|
||||
w.Header().Set("Server", "Minio")
|
||||
w.Header().Set("Connection", "close")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
case drivers.BucketNameInvalid:
|
||||
{
|
||||
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
case drivers.BucketNotFound:
|
||||
{
|
||||
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
default:
|
||||
{
|
||||
log.Error.Println(iodine.New(err, nil))
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ func pathMux(api minioAPI, mux *router.Router) *router.Router {
|
||||
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
|
||||
mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET")
|
||||
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
|
||||
mux.HandleFunc("/{bucket}", api.headBucketHandler).Methods("HEAD")
|
||||
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
|
||||
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD")
|
||||
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
|
||||
@@ -56,6 +57,7 @@ func domainMux(api minioAPI, mux *router.Router) *router.Router {
|
||||
api.putObjectHandler).Host("{bucket}" + "." + api.domain).Methods("PUT")
|
||||
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
|
||||
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
|
||||
mux.HandleFunc("/{bucket}", api.headBucketHandler).Methods("HEAD")
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
||||
"github.com/fkautz/testify/mock"
|
||||
"github.com/minio-io/minio/pkg/api"
|
||||
"github.com/minio-io/objectdriver"
|
||||
"github.com/minio-io/objectdriver/donut"
|
||||
"github.com/minio-io/objectdriver/file"
|
||||
"github.com/minio-io/objectdriver/memory"
|
||||
"github.com/minio-io/objectdriver/mocks"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
. "github.com/minio-io/check"
|
||||
)
|
||||
@@ -177,6 +177,33 @@ func (s *MySuite) TestEmptyObject(c *C) {
|
||||
verifyHeaders(c, response.Header, resMetadata.Created, 0, "application/octet-stream", resMetadata.Md5)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestBucket(c *C) {
|
||||
switch driver := s.Driver.(type) {
|
||||
case *mocks.Driver:
|
||||
{
|
||||
driver.AssertExpectations(c)
|
||||
}
|
||||
}
|
||||
driver := s.Driver
|
||||
typedDriver := s.MockDriver
|
||||
metadata := drivers.BucketMetadata{
|
||||
Name: "bucket",
|
||||
Created: time.Now(),
|
||||
}
|
||||
typedDriver.On("CreateBucket", "bucket").Return(nil).Once()
|
||||
typedDriver.On("GetBucketMetadata", "bucket").Return(metadata, nil).Twice()
|
||||
|
||||
httpHandler := api.HTTPHandler("", driver)
|
||||
testServer := httptest.NewServer(httpHandler)
|
||||
defer testServer.Close()
|
||||
|
||||
driver.CreateBucket("bucket")
|
||||
|
||||
response, err := http.Head(testServer.URL + "/bucket")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestObject(c *C) {
|
||||
switch driver := s.Driver.(type) {
|
||||
case *mocks.Driver:
|
||||
|
||||
Reference in New Issue
Block a user