aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2024-03-02 18:02:01 +0100
committerGitHub <noreply@github.com>2024-03-02 17:02:01 +0000
commit70c126e6184872a6ac63cae2f327fc745b25d1d7 (patch)
treefd33ef9f000075dbd06693c0834a8521369df709 /tests
parent6465f94a2d26cdacc232fddc20f98d98df61ddac (diff)
downloadgitea-70c126e6184872a6ac63cae2f327fc745b25d1d7.tar.gz
gitea-70c126e6184872a6ac63cae2f327fc745b25d1d7.zip
Add support for API blob upload of release attachments (#29507)
Fixes #29502 Our endpoint is not Github compatible. https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_releases_test.go68
1 files changed, 52 insertions, 16 deletions
diff --git a/tests/integration/api_releases_test.go b/tests/integration/api_releases_test.go
index 5b1ab76ce9..49aa4c4e1b 100644
--- a/tests/integration/api_releases_test.go
+++ b/tests/integration/api_releases_test.go
@@ -262,24 +262,60 @@ func TestAPIUploadAssetRelease(t *testing.T) {
filename := "image.png"
buff := generateImg()
- body := &bytes.Buffer{}
- writer := multipart.NewWriter(body)
- part, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
- _, err = io.Copy(part, &buff)
- assert.NoError(t, err)
- err = writer.Close()
- assert.NoError(t, err)
+ assetURL := fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d/assets", owner.Name, repo.Name, r.ID)
- req := NewRequestWithBody(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d/assets?name=test-asset", owner.Name, repo.Name, r.ID), body).
- AddTokenAuth(token)
- req.Header.Add("Content-Type", writer.FormDataContentType())
- resp := MakeRequest(t, req, http.StatusCreated)
+ t.Run("multipart/form-data", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ body := &bytes.Buffer{}
+
+ writer := multipart.NewWriter(body)
+ part, err := writer.CreateFormFile("attachment", filename)
+ assert.NoError(t, err)
+ _, err = io.Copy(part, bytes.NewReader(buff.Bytes()))
+ assert.NoError(t, err)
+ err = writer.Close()
+ assert.NoError(t, err)
+
+ req := NewRequestWithBody(t, http.MethodPost, assetURL, bytes.NewReader(body.Bytes())).
+ AddTokenAuth(token).
+ SetHeader("Content-Type", writer.FormDataContentType())
+ resp := MakeRequest(t, req, http.StatusCreated)
+
+ var attachment *api.Attachment
+ DecodeJSON(t, resp, &attachment)
+
+ assert.EqualValues(t, filename, attachment.Name)
+ assert.EqualValues(t, 104, attachment.Size)
+
+ req = NewRequestWithBody(t, http.MethodPost, assetURL+"?name=test-asset", bytes.NewReader(body.Bytes())).
+ AddTokenAuth(token).
+ SetHeader("Content-Type", writer.FormDataContentType())
+ resp = MakeRequest(t, req, http.StatusCreated)
+
+ var attachment2 *api.Attachment
+ DecodeJSON(t, resp, &attachment2)
+
+ assert.EqualValues(t, "test-asset", attachment2.Name)
+ assert.EqualValues(t, 104, attachment2.Size)
+ })
+
+ t.Run("application/octet-stream", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ req := NewRequestWithBody(t, http.MethodPost, assetURL, bytes.NewReader(buff.Bytes())).
+ AddTokenAuth(token)
+ MakeRequest(t, req, http.StatusBadRequest)
+
+ req = NewRequestWithBody(t, http.MethodPost, assetURL+"?name=stream.bin", bytes.NewReader(buff.Bytes())).
+ AddTokenAuth(token)
+ resp := MakeRequest(t, req, http.StatusCreated)
- var attachment *api.Attachment
- DecodeJSON(t, resp, &attachment)
+ var attachment *api.Attachment
+ DecodeJSON(t, resp, &attachment)
- assert.EqualValues(t, "test-asset", attachment.Name)
- assert.EqualValues(t, 104, attachment.Size)
+ assert.EqualValues(t, "stream.bin", attachment.Name)
+ assert.EqualValues(t, 104, attachment.Size)
+ })
}