diff options
author | zeripath <art27@cantab.net> | 2020-10-26 11:13:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 19:13:39 +0800 |
commit | 5178aa2130e319a54761d64944408beda390f259 (patch) | |
tree | e4d3a1cf1223a2296a04eb3296137db3adaa2689 | |
parent | 5da8a84328a4d45c124d28c50dd71af111a7ca8c (diff) | |
download | gitea-5178aa2130e319a54761d64944408beda390f259.tar.gz gitea-5178aa2130e319a54761d64944408beda390f259.zip |
Attempt to handle unready PR in tests (#13305) (#13310)
Backport #13305
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
-rw-r--r-- | integrations/api_helper_for_declarative_test.go | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/integrations/api_helper_for_declarative_test.go b/integrations/api_helper_for_declarative_test.go index 51335c8216..b0031ef332 100644 --- a/integrations/api_helper_for_declarative_test.go +++ b/integrations/api_helper_for_declarative_test.go @@ -5,14 +5,17 @@ package integrations import ( + "context" "encoding/json" "fmt" "io/ioutil" "net/http" "testing" + "time" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" + "code.gitea.io/gitea/modules/queue" api "code.gitea.io/gitea/modules/structs" "github.com/stretchr/testify/assert" @@ -225,11 +228,25 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64) Do: string(models.MergeStyleMerge), }) - if ctx.ExpectedCode != 0 { - ctx.Session.MakeRequest(t, req, ctx.ExpectedCode) - return + resp := ctx.Session.MakeRequest(t, req, NoExpectedStatus) + + if resp.Code == http.StatusMethodNotAllowed { + err := api.APIError{} + DecodeJSON(t, resp, &err) + assert.EqualValues(t, "Please try again later", err.Message) + queue.GetManager().FlushAll(context.Background(), 5*time.Second) + resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus) + } + + expected := ctx.ExpectedCode + if expected == 0 { + expected = 200 + } + + if !assert.EqualValues(t, expected, resp.Code, + "Request: %s %s", req.Method, req.URL.String()) { + logUnexpectedResponse(t, resp) } - ctx.Session.MakeRequest(t, req, 200) } } |