summaryrefslogtreecommitdiffstats
path: root/tests/integration
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2023-04-29 04:38:22 +0200
committerGitHub <noreply@github.com>2023-04-28 22:38:22 -0400
commit0bd05a9f1cbf7839d943e5812f84bdeb7d95dfee (patch)
treef29f00551289ef3dcd4a7bfd4c38532fa8204ad4 /tests/integration
parentef9e0ce9c93ed2209adaf69094e909e053110990 (diff)
downloadgitea-0bd05a9f1cbf7839d943e5812f84bdeb7d95dfee.tar.gz
gitea-0bd05a9f1cbf7839d943e5812f84bdeb7d95dfee.zip
Add integration test for API raw content reference formats (#24388)
This pull request adds an integration test to validate the behavior of raw content API's reference handling for all supported formats . close #24242 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/api_repo_get_contents_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/integration/api_repo_get_contents_test.go b/tests/integration/api_repo_get_contents_test.go
index f7d9c716aa..8b193b03c9 100644
--- a/tests/integration/api_repo_get_contents_test.go
+++ b/tests/integration/api_repo_get_contents_test.go
@@ -4,6 +4,7 @@
package integration
import (
+ "io"
"net/http"
"net/url"
"testing"
@@ -159,3 +160,30 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
MakeRequest(t, req, http.StatusOK)
}
+
+func TestAPIGetContentsRefFormats(t *testing.T) {
+ onGiteaRun(t, func(t *testing.T, u *url.URL) {
+ file := "README.md"
+ sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
+ content := "# repo1\n\nDescription for repo1"
+
+ noRef := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + file
+ refInPath := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + sha + "/" + file
+ refInQuery := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + file + "?ref=" + sha
+
+ resp := MakeRequest(t, NewRequest(t, http.MethodGet, noRef), http.StatusOK)
+ raw, err := io.ReadAll(resp.Body)
+ assert.NoError(t, err)
+ assert.EqualValues(t, content, string(raw))
+
+ resp = MakeRequest(t, NewRequest(t, http.MethodGet, refInPath), http.StatusOK)
+ raw, err = io.ReadAll(resp.Body)
+ assert.NoError(t, err)
+ assert.EqualValues(t, content, string(raw))
+
+ resp = MakeRequest(t, NewRequest(t, http.MethodGet, refInQuery), http.StatusOK)
+ raw, err = io.ReadAll(resp.Body)
+ assert.NoError(t, err)
+ assert.EqualValues(t, content, string(raw))
+ })
+}