Commit e074ee8b authored by Steve Abrams's avatar Steve Abrams Committed by Jacob Vosmaer

Add RubyGems upload route

Add upload route for RubyGems accelerated
uploads.
parent 42e7b65b
---
title: Add RubyGems registry upload route
merge_request: 680
author:
type: added
...@@ -264,6 +264,9 @@ func (u *upstream) configureRoutes() { ...@@ -264,6 +264,9 @@ func (u *upstream) configureRoutes() {
// Debian Artifact Repository // Debian Artifact Repository
u.route("PUT", apiPattern+`v4/projects/[0-9]+/packages/debian/`, upload.BodyUploader(api, signingProxy, preparers.packages)), u.route("PUT", apiPattern+`v4/projects/[0-9]+/packages/debian/`, upload.BodyUploader(api, signingProxy, preparers.packages)),
// Gem Artifact Repository
u.route("POST", apiPattern+`v4/projects/[0-9]+/packages/rubygems/`, upload.BodyUploader(api, signingProxy, preparers.packages)),
// We are porting API to disk acceleration // We are porting API to disk acceleration
// we need to declare each routes until we have fixed all the routes on the rails codebase. // we need to declare each routes until we have fixed all the routes on the rails codebase.
// Overall status can be seen at https://gitlab.com/groups/gitlab-org/-/epics/1802#current-status // Overall status can be seen at https://gitlab.com/groups/gitlab-org/-/epics/1802#current-status
......
...@@ -292,9 +292,9 @@ func TestLfsUpload(t *testing.T) { ...@@ -292,9 +292,9 @@ func TestLfsUpload(t *testing.T) {
require.Equal(t, rspBody, string(rspData)) require.Equal(t, rspBody, string(rspData))
} }
func packageUploadTestServer(t *testing.T, resource string, reqBody string, rspBody string) *httptest.Server { func packageUploadTestServer(t *testing.T, method string, resource string, reqBody string, rspBody string) *httptest.Server {
return testhelper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, r *http.Request) { return testhelper.TestServerWithHandler(regexp.MustCompile(`.`), func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, r.Method, "PUT") require.Equal(t, r.Method, method)
apiResponse := fmt.Sprintf( apiResponse := fmt.Sprintf(
`{"TempPath":%q, "Size": %d}`, scratchDir, len(reqBody), `{"TempPath":%q, "Size": %d}`, scratchDir, len(reqBody),
) )
...@@ -330,17 +330,17 @@ func packageUploadTestServer(t *testing.T, resource string, reqBody string, rspB ...@@ -330,17 +330,17 @@ func packageUploadTestServer(t *testing.T, resource string, reqBody string, rspB
}) })
} }
func testPackageFileUpload(t *testing.T, resource string) { func testPackageFileUpload(t *testing.T, method string, resource string) {
reqBody := "test data" reqBody := "test data"
rspBody := "test success" rspBody := "test success"
ts := packageUploadTestServer(t, resource, reqBody, rspBody) ts := packageUploadTestServer(t, method, resource, reqBody, rspBody)
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
defer ws.Close() defer ws.Close()
req, err := http.NewRequest("PUT", ws.URL+resource, strings.NewReader(reqBody)) req, err := http.NewRequest(method, ws.URL+resource, strings.NewReader(reqBody))
require.NoError(t, err) require.NoError(t, err)
resp, err := http.DefaultClient.Do(req) resp, err := http.DefaultClient.Do(req)
...@@ -355,15 +355,19 @@ func testPackageFileUpload(t *testing.T, resource string) { ...@@ -355,15 +355,19 @@ func testPackageFileUpload(t *testing.T, resource string) {
} }
func TestPackageFilesUpload(t *testing.T) { func TestPackageFilesUpload(t *testing.T) {
routes := []string{ routes := []struct {
"/api/v4/packages/conan/v1/files", method string
"/api/v4/projects/2412/packages/conan/v1/files", resource string
"/api/v4/projects/2412/packages/maven/v1/files", }{
"/api/v4/projects/2412/packages/generic/mypackage/0.0.1/myfile.tar.gz", {"PUT", "/api/v4/packages/conan/v1/files"},
"/api/v4/projects/2412/packages/debian/libsample0_1.2.3~alpha2-1_amd64.deb", {"PUT", "/api/v4/projects/2412/packages/conan/v1/files"},
{"PUT", "/api/v4/projects/2412/packages/maven/v1/files"},
{"PUT", "/api/v4/projects/2412/packages/generic/mypackage/0.0.1/myfile.tar.gz"},
{"PUT", "/api/v4/projects/2412/packages/debian/libsample0_1.2.3~alpha2-1_amd64.deb"},
{"POST", "/api/v4/projects/2412/packages/rubygems/api/v1/gems/sample.gem"},
} }
for _, r := range routes { for _, r := range routes {
testPackageFileUpload(t, r) testPackageFileUpload(t, r.method, r.resource)
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment