diff options
author | Matthew Walowski <mattwalowski@gmail.com> | 2023-05-08 00:10:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 07:10:53 +0000 |
commit | ff5629268c5c01d3f460570baa571baef3f896cd (patch) | |
tree | d0e85b7ca946b93bc7d74d30436aabcebb59dc27 /tests/integration | |
parent | e962ade99cfd0471273f3dcf956c7cd222472758 (diff) | |
download | gitea-ff5629268c5c01d3f460570baa571baef3f896cd.tar.gz gitea-ff5629268c5c01d3f460570baa571baef3f896cd.zip |
Pass 'not' to commit count (#24473)
Due to #24409 , we can now specify '--not' when getting all commits from
a repo to exclude commits from a different branch.
When I wrote that PR, I forgot to also update the code that counts the
number of commits in the repo. So now, if the --not option is used, it
may return too many commits, which can indicate that another page of
data is available when it is not.
This PR passes --not to the commands that count the number of commits in
a repo
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/api_repo_git_commits_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/integration/api_repo_git_commits_test.go b/tests/integration/api_repo_git_commits_test.go index 17750a2799..d9c3d7b952 100644 --- a/tests/integration/api_repo_git_commits_test.go +++ b/tests/integration/api_repo_git_commits_test.go @@ -59,6 +59,29 @@ func TestAPIReposGitCommitList(t *testing.T) { token := getTokenForLoggedInUser(t, session) // Test getting commits (Page 1) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo20/commits?token="+token+"¬=master&sha=remove-files-a", user.Name) + resp := MakeRequest(t, req, http.StatusOK) + + var apiData []api.Commit + DecodeJSON(t, resp, &apiData) + + assert.Len(t, apiData, 2) + assert.EqualValues(t, "cfe3b3c1fd36fba04f9183287b106497e1afe986", apiData[0].CommitMeta.SHA) + compareCommitFiles(t, []string{"link_hi", "test.csv"}, apiData[0].Files) + assert.EqualValues(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[1].CommitMeta.SHA) + compareCommitFiles(t, []string{"test.csv"}, apiData[1].Files) + + assert.EqualValues(t, resp.Header().Get("X-Total"), "2") +} + +func TestAPIReposGitCommitListNotMaster(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) + + // Test getting commits (Page 1) req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?token="+token, user.Name) resp := MakeRequest(t, req, http.StatusOK) @@ -72,6 +95,8 @@ func TestAPIReposGitCommitList(t *testing.T) { compareCommitFiles(t, []string{"readme.md"}, apiData[1].Files) assert.EqualValues(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA) compareCommitFiles(t, []string{"readme.md"}, apiData[2].Files) + + assert.EqualValues(t, resp.Header().Get("X-Total"), "3") } func TestAPIReposGitCommitListPage2Empty(t *testing.T) { @@ -148,4 +173,26 @@ func TestGetFileHistory(t *testing.T) { assert.Len(t, apiData, 1) assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA) compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files) + + assert.EqualValues(t, resp.Header().Get("X-Total"), "1") +} + +func TestGetFileHistoryNotOnMaster(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) + + req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo20/commits?path=test.csv&token="+token+"&sha=add-csv¬=master", user.Name) + resp := MakeRequest(t, req, http.StatusOK) + + var apiData []api.Commit + DecodeJSON(t, resp, &apiData) + + assert.Len(t, apiData, 1) + assert.Equal(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[0].CommitMeta.SHA) + compareCommitFiles(t, []string{"test.csv"}, apiData[0].Files) + + assert.EqualValues(t, resp.Header().Get("X-Total"), "1") } |