summaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2019-08-09 04:13:03 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2019-08-09 10:13:03 +0800
commit2b6f45299d6e96b633a309d68055f9ae0699b8f2 (patch)
tree85ebd068cafb64fdd987b36541a9e743f0744f4c /integrations
parentc534b7e211d3264bbbde9b95cd8d6e9e60ad4215 (diff)
downloadgitea-2b6f45299d6e96b633a309d68055f9ae0699b8f2.tar.gz
gitea-2b6f45299d6e96b633a309d68055f9ae0699b8f2.zip
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>
Diffstat (limited to 'integrations')
-rw-r--r--integrations/repo_commits_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/integrations/repo_commits_test.go b/integrations/repo_commits_test.go
index 1f70d69251..7a4761adc6 100644
--- a/integrations/repo_commits_test.go
+++ b/integrations/repo_commits_test.go
@@ -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) {