Skip to content

Commit 0bd05a9

Browse files
6543lunny
andauthored
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 <[email protected]>
1 parent ef9e0ce commit 0bd05a9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/integration/api_repo_get_contents_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package integration
55

66
import (
7+
"io"
78
"net/http"
89
"net/url"
910
"testing"
@@ -159,3 +160,30 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
159160
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
160161
MakeRequest(t, req, http.StatusOK)
161162
}
163+
164+
func TestAPIGetContentsRefFormats(t *testing.T) {
165+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
166+
file := "README.md"
167+
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
168+
content := "# repo1\n\nDescription for repo1"
169+
170+
noRef := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + file
171+
refInPath := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + sha + "/" + file
172+
refInQuery := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + file + "?ref=" + sha
173+
174+
resp := MakeRequest(t, NewRequest(t, http.MethodGet, noRef), http.StatusOK)
175+
raw, err := io.ReadAll(resp.Body)
176+
assert.NoError(t, err)
177+
assert.EqualValues(t, content, string(raw))
178+
179+
resp = MakeRequest(t, NewRequest(t, http.MethodGet, refInPath), http.StatusOK)
180+
raw, err = io.ReadAll(resp.Body)
181+
assert.NoError(t, err)
182+
assert.EqualValues(t, content, string(raw))
183+
184+
resp = MakeRequest(t, NewRequest(t, http.MethodGet, refInQuery), http.StatusOK)
185+
raw, err = io.ReadAll(resp.Body)
186+
assert.NoError(t, err)
187+
assert.EqualValues(t, content, string(raw))
188+
})
189+
}

0 commit comments

Comments
 (0)