mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 00:55:27 +00:00
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>
This commit is contained in:
parent
ef9e0ce9c9
commit
0bd05a9f1c
|
@ -4,6 +4,7 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"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)
|
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
|
||||||
MakeRequest(t, req, http.StatusOK)
|
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))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue