diff options
author | 6543 <6543@obermui.de> | 2020-04-08 04:54:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-07 22:54:46 -0400 |
commit | 3d63caa54245d87dd057d4e853bb5dc7fc39e7db (patch) | |
tree | 2fbbb48a39cff157f8cf171b0dad51af366c0908 /integrations/api_repo_git_commits_test.go | |
parent | 71979d9663d8e43b772c37f2a79af5b8911df661 (diff) | |
download | gitea-3d63caa54245d87dd057d4e853bb5dc7fc39e7db.tar.gz gitea-3d63caa54245d87dd057d4e853bb5dc7fc39e7db.zip |
[API] Get a single commit via Ref (#10915)
* GET /repos/:owner/:repo/commits/:ref
* add Validation Checks
* Fix & Extend TEST
* add two new tast cases
Diffstat (limited to 'integrations/api_repo_git_commits_test.go')
-rw-r--r-- | integrations/api_repo_git_commits_test.go | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/integrations/api_repo_git_commits_test.go b/integrations/api_repo_git_commits_test.go index 5291b8f4ac..f710811ea7 100644 --- a/integrations/api_repo_git_commits_test.go +++ b/integrations/api_repo_git_commits_test.go @@ -21,17 +21,41 @@ func TestAPIReposGitCommits(t *testing.T) { session := loginUser(t, user.Name) token := getTokenForLoggedInUser(t, session) + //check invalid requests for GetCommitsBySHA + req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/commits/master?token="+token, user.Name) + session.MakeRequest(t, req, http.StatusUnprocessableEntity) + + req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/commits/12345?token="+token, user.Name) + session.MakeRequest(t, req, http.StatusNotFound) + + //check invalid requests for GetCommitsByRef + req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/commits/..?token="+token, user.Name) + session.MakeRequest(t, req, http.StatusUnprocessableEntity) + + req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/commits/branch-not-exist?token="+token, user.Name) + session.MakeRequest(t, req, http.StatusNotFound) + for _, ref := range [...]string{ - "commits/master", // Branch - "commits/v1.1", // Tag + "master", // Branch + "v1.1", // Tag + "65f1", // short sha + "65f1bf27bc3bf70f64657658635e66094edbcb4d", // full sha } { - req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/%s?token="+token, user.Name, ref) - session.MakeRequest(t, req, http.StatusOK) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/commits/%s?token="+token, user.Name, ref) + resp := session.MakeRequest(t, req, http.StatusOK) + commitByRef := new(api.Commit) + DecodeJSON(t, resp, commitByRef) + assert.Len(t, commitByRef.SHA, 40) + assert.EqualValues(t, commitByRef.SHA, commitByRef.RepoCommit.Tree.SHA) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/commits/%s?token="+token, user.Name, commitByRef.SHA) + resp = session.MakeRequest(t, req, http.StatusOK) + commitBySHA := new(api.Commit) + DecodeJSON(t, resp, commitBySHA) + + assert.EqualValues(t, commitByRef.SHA, commitBySHA.SHA) + assert.EqualValues(t, commitByRef.HTMLURL, commitBySHA.HTMLURL) + assert.EqualValues(t, commitByRef.RepoCommit.Message, commitBySHA.RepoCommit.Message) } - - // Test getting non-existent refs - req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/commits/unknown?token="+token, user.Name) - session.MakeRequest(t, req, http.StatusNotFound) } func TestAPIReposGitCommitList(t *testing.T) { |