aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-07-13 09:14:14 +0200
committerGitHub <noreply@github.com>2021-07-13 08:14:14 +0100
commitb81106be3faadf7821c30b18fb1cec6c27041896 (patch)
tree4e6198ec7013999bf8c85d79a00c4c14ea55c07a /integrations
parent4ce32c9e93591f2449a388201c323ca193f59c07 (diff)
downloadgitea-b81106be3faadf7821c30b18fb1cec6c27041896.tar.gz
gitea-b81106be3faadf7821c30b18fb1cec6c27041896.zip
Let branch/tag name be a valid ref to get CI status (#16400)
* fix #16384# * refactor: move shared helper func to utils package * extend Tests * use ctx.Repo.GitRepo if not nil
Diffstat (limited to 'integrations')
-rw-r--r--integrations/repo_commits_test.go38
1 files changed, 24 insertions, 14 deletions
diff --git a/integrations/repo_commits_test.go b/integrations/repo_commits_test.go
index 306175d812..8dcbcd3683 100644
--- a/integrations/repo_commits_test.go
+++ b/integrations/repo_commits_test.go
@@ -73,26 +73,36 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
//By SHA
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)+"/statuses")
- testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), state)
+ reqOne := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)+"/status")
+ testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
+
//By Ref
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/statuses")
- testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), state)
+ reqOne = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/status")
+ testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/v1.1/statuses")
- testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), state)
+ reqOne = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/v1.1/status")
+ testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
}
-func testRepoCommitsWithStatus(t *testing.T, resp *httptest.ResponseRecorder, state string) {
+func testRepoCommitsWithStatus(t *testing.T, resp, respOne *httptest.ResponseRecorder, state string) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
- decoder := json.NewDecoder(resp.Body)
- statuses := []*api.CommitStatus{}
- assert.NoError(t, decoder.Decode(&statuses))
- assert.Len(t, statuses, 1)
- for _, s := range statuses {
- assert.Equal(t, api.CommitStatusState(state), s.State)
- assert.Equal(t, setting.AppURL+"api/v1/repos/user2/repo1/statuses/65f1bf27bc3bf70f64657658635e66094edbcb4d", s.URL)
- assert.Equal(t, "http://test.ci/", s.TargetURL)
- assert.Equal(t, "", s.Description)
- assert.Equal(t, "testci", s.Context)
+ var statuses []*api.CommitStatus
+ assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &statuses))
+ var status api.CombinedStatus
+ assert.NoError(t, json.Unmarshal(respOne.Body.Bytes(), &status))
+ assert.NotNil(t, status)
+
+ if assert.Len(t, statuses, 1) {
+ assert.Equal(t, api.CommitStatusState(state), statuses[0].State)
+ assert.Equal(t, setting.AppURL+"api/v1/repos/user2/repo1/statuses/65f1bf27bc3bf70f64657658635e66094edbcb4d", statuses[0].URL)
+ assert.Equal(t, "http://test.ci/", statuses[0].TargetURL)
+ assert.Equal(t, "", statuses[0].Description)
+ assert.Equal(t, "testci", statuses[0].Context)
+
+ assert.Len(t, status.Statuses, 1)
+ assert.Equal(t, statuses[0], status.Statuses[0])
+ assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", status.SHA)
}
}