From 361d10cc786249fbb084a6961a764680c3218d59 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 20 Jul 2023 12:08:45 +0300 Subject: [PATCH] [#174] Fix query for listing multipart uploads Signed-off-by: Denis Kirillov --- api/router.go | 2 +- api/router_mock_test.go | 30 +++++++++++++++++++++--------- api/router_test.go | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/api/router.go b/api/router.go index 9d7c76ea..1a6b44cd 100644 --- a/api/router.go +++ b/api/router.go @@ -165,7 +165,7 @@ func bucketRouter(h Handler, log *zap.Logger) chi.Router { bktRouter.Group(func(r chi.Router) { r.Method(http.MethodGet, "/", NewHandlerFilter(). Add(NewFilter(). - Queries("upload"). + Queries("uploads"). Handler(named("ListMultipartUploads", h.ListMultipartUploadsHandler))). Add(NewFilter(). Queries("location"). diff --git a/api/router_mock_test.go b/api/router_mock_test.go index 3c84921d..0ba5386c 100644 --- a/api/router_mock_test.go +++ b/api/router_mock_test.go @@ -222,9 +222,13 @@ func (h *handlerMock) ListObjectsV2MHandler(http.ResponseWriter, *http.Request) panic("implement me") } -func (h *handlerMock) ListObjectsV2Handler(http.ResponseWriter, *http.Request) { - //TODO implement me - panic("implement me") +func (h *handlerMock) ListObjectsV2Handler(w http.ResponseWriter, r *http.Request) { + res := &handlerResult{ + Method: "ListObjectsV2", + ReqInfo: middleware.GetReqInfo(r.Context()), + } + + h.writeResponse(w, res) } func (h *handlerMock) ListBucketObjectVersionsHandler(http.ResponseWriter, *http.Request) { @@ -232,9 +236,13 @@ func (h *handlerMock) ListBucketObjectVersionsHandler(http.ResponseWriter, *http panic("implement me") } -func (h *handlerMock) ListObjectsV1Handler(http.ResponseWriter, *http.Request) { - //TODO implement me - panic("implement me") +func (h *handlerMock) ListObjectsV1Handler(w http.ResponseWriter, r *http.Request) { + res := &handlerResult{ + Method: "ListObjectsV1", + ReqInfo: middleware.GetReqInfo(r.Context()), + } + + h.writeResponse(w, res) } func (h *handlerMock) PutBucketLifecycleHandler(http.ResponseWriter, *http.Request) { @@ -359,9 +367,13 @@ func (h *handlerMock) ListPartsHandler(http.ResponseWriter, *http.Request) { panic("implement me") } -func (h *handlerMock) ListMultipartUploadsHandler(http.ResponseWriter, *http.Request) { - //TODO implement me - panic("implement me") +func (h *handlerMock) ListMultipartUploadsHandler(w http.ResponseWriter, r *http.Request) { + res := &handlerResult{ + Method: "ListMultipartUploads", + ReqInfo: middleware.GetReqInfo(r.Context()), + } + + h.writeResponse(w, res) } func (h *handlerMock) ResolveBucket(context.Context, string) (*data.BucketInfo, error) { diff --git a/api/router_test.go b/api/router_test.go index e63007e0..2142485e 100644 --- a/api/router_test.go +++ b/api/router_test.go @@ -32,6 +32,20 @@ func TestRouterUploadPart(t *testing.T) { require.Equal(t, "UploadPart", resp.Method) } +func TestRouterListMultipartUploads(t *testing.T) { + chiRouter := prepareRouter(t) + + w := httptest.NewRecorder() + r := httptest.NewRequest(http.MethodGet, "/test-bucket", nil) + query := make(url.Values) + query.Set("uploads", "") + r.URL.RawQuery = query.Encode() + + chiRouter.ServeHTTP(w, r) + resp := readResponse(t, w) + require.Equal(t, "ListMultipartUploads", resp.Method) +} + func TestRouterObjectWithSlashes(t *testing.T) { chiRouter := prepareRouter(t)