|
4 | 4 | package integration
|
5 | 5 |
|
6 | 6 | import (
|
| 7 | + "io" |
7 | 8 | "net/http"
|
8 | 9 | "net/url"
|
9 | 10 | "testing"
|
@@ -159,3 +160,30 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
|
159 | 160 | req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
|
160 | 161 | MakeRequest(t, req, http.StatusOK)
|
161 | 162 | }
|
| 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