From be183bb715b85ee32cc0086145f7cc098d213220 Mon Sep 17 00:00:00 2001 From: kawmra Date: Sat, 16 Nov 2024 23:43:38 +0900 Subject: [PATCH] Add support for canceling resumable uploads --- fakestorage/server.go | 2 ++ fakestorage/upload.go | 4 ++++ fakestorage/upload_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/fakestorage/server.go b/fakestorage/server.go index 4283ccf030..fa05b79472 100644 --- a/fakestorage/server.go +++ b/fakestorage/server.go @@ -304,6 +304,8 @@ func (s *Server) buildMuxer() { handler.Path("/upload/storage/v1/b/{bucketName}/o/").Methods(http.MethodPost).HandlerFunc(jsonToHTTPHandler(s.insertObject)) handler.Path("/upload/storage/v1/b/{bucketName}/o").Methods(http.MethodPut).HandlerFunc(jsonToHTTPHandler(s.uploadFileContent)) handler.Path("/upload/storage/v1/b/{bucketName}/o/").Methods(http.MethodPut).HandlerFunc(jsonToHTTPHandler(s.uploadFileContent)) + handler.Path("/upload/storage/v1/b/{bucketName}/o").Methods(http.MethodDelete).HandlerFunc(jsonToHTTPHandler(s.deleteResumableUpload)) + handler.Path("/upload/storage/v1/b/{bucketName}/o/").Methods(http.MethodDelete).HandlerFunc(jsonToHTTPHandler(s.deleteResumableUpload)) handler.Path("/upload/resumable/{uploadId}").Methods(http.MethodPut, http.MethodPost).HandlerFunc(jsonToHTTPHandler(s.uploadFileContent)) // Batch endpoint diff --git a/fakestorage/upload.go b/fakestorage/upload.go index e9181df46f..07bd788f66 100644 --- a/fakestorage/upload.go +++ b/fakestorage/upload.go @@ -630,6 +630,10 @@ func parseContentRange(r string) (parsed contentRange, err error) { return parsed, nil } +func (s *Server) deleteResumableUpload(r *http.Request) jsonResponse { + return jsonResponse{status: 499} +} + func loadMetadata(rc io.ReadCloser) (*multipartMetadata, error) { defer rc.Close() var m multipartMetadata diff --git a/fakestorage/upload_test.go b/fakestorage/upload_test.go index 6e2e2d8dd6..1e9cf23b09 100644 --- a/fakestorage/upload_test.go +++ b/fakestorage/upload_test.go @@ -720,6 +720,30 @@ func TestServerClientSimpleUploadNoName(t *testing.T) { } } +func TestServerClientDeleteResumableUpload(t *testing.T) { + server := NewServer(nil) + defer server.Stop() + + req, err := http.NewRequest("DELETE", server.URL()+"/upload/storage/v1/b/other-bucket/o?uploadType=media&name=some/nice/object.txt", nil) + if err != nil { + t.Fatal(err) + } + client := http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + }, + } + resp, err := client.Do(req) + if err != nil { + t.Fatal(err) + } + defer resp.Body.Close() + expectedStatus := 499 + if resp.StatusCode != expectedStatus { + t.Errorf("wrong status code\nwant %d\ngot %d", expectedStatus, resp.StatusCode) + } +} + func TestServerInvalidUploadType(t *testing.T) { server := NewServer(nil) defer server.Stop()