mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-03 08:03:34 +00:00
fix: Improve since/until when counting commits for X-Total-Count (#38243)
Follow up for https://github.com/go-gitea/gitea/pull/38204. --------- Signed-off-by: puni9869 <80308335+puni9869@users.noreply.github.com>
This commit is contained in:
@@ -241,3 +241,27 @@ func TestGetFileHistoryNotOnMaster(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "1", resp.Header().Get("X-Total"))
|
||||
}
|
||||
|
||||
func TestGetFileHistoryEmptyDateRange(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
// Login as User2.
|
||||
session := loginUser(t, user.Name)
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
||||
|
||||
// readme.md exists in repo16 but no commits fall before 1970, so the date
|
||||
// filter yields an empty range: this must return 200 with an empty list,
|
||||
// not 404 (regression: a valid path with an empty date range was a 404).
|
||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?path=readme.md&sha=good-sign&until=1970-01-01T00:00:00Z", user.Name).
|
||||
AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
apiData := DecodeJSON(t, resp, []api.Commit{})
|
||||
assert.Empty(t, apiData)
|
||||
assert.Equal(t, "0", resp.Header().Get("X-Total"))
|
||||
|
||||
// a path that does not exist must still return 404 even with a date filter
|
||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?path=does-not-exist.md&sha=good-sign&until=1970-01-01T00:00:00Z", user.Name).
|
||||
AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user