mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
api: fix multiple bugs with statuses endpoints (#7785)
* fix commit statuses api url * search refs before passing sha * adjust tests * directly search tags and branches names + remove un-needed check in NewCommitStatus * fix comment * de-duplicate code * test: use relative setting.AppURL * Update routers/api/v1/repo/status.go Co-Authored-By: Lauris BH <lauris@nix.lv> * remove return * Update routers/api/v1/repo/status.go Co-Authored-By: Lauris BH <lauris@nix.lv>
This commit is contained in:
committed by
Lunny Xiao
parent
c534b7e211
commit
2b6f45299d
@@ -5,10 +5,13 @@
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -67,6 +70,29 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||
for _, class := range classes {
|
||||
assert.True(t, sel.HasClass(class))
|
||||
}
|
||||
|
||||
//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)
|
||||
//By Ref
|
||||
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/statuses")
|
||||
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, 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)
|
||||
}
|
||||
|
||||
func testRepoCommitsWithStatus(t *testing.T, resp *httptest.ResponseRecorder, state string) {
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
statuses := []*api.Status{}
|
||||
assert.NoError(t, decoder.Decode(&statuses))
|
||||
assert.Len(t, statuses, 1)
|
||||
for _, s := range statuses {
|
||||
assert.Equal(t, api.StatusState(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)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoCommitsWithStatusPending(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user