|
5 | 5 | package integrations |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "context" |
8 | 9 | "encoding/json" |
9 | 10 | "fmt" |
10 | 11 | "io/ioutil" |
11 | 12 | "net/http" |
12 | 13 | "testing" |
| 14 | + "time" |
13 | 15 |
|
14 | 16 | "code.gitea.io/gitea/models" |
15 | 17 | "code.gitea.io/gitea/modules/auth" |
| 18 | + "code.gitea.io/gitea/modules/queue" |
16 | 19 | api "code.gitea.io/gitea/modules/structs" |
17 | 20 |
|
18 | 21 | "github.com/stretchr/testify/assert" |
@@ -224,11 +227,25 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64) |
224 | 227 | Do: string(models.MergeStyleMerge), |
225 | 228 | }) |
226 | 229 |
|
227 | | - if ctx.ExpectedCode != 0 { |
228 | | - ctx.Session.MakeRequest(t, req, ctx.ExpectedCode) |
229 | | - return |
| 230 | + resp := ctx.Session.MakeRequest(t, req, NoExpectedStatus) |
| 231 | + |
| 232 | + if resp.Code == http.StatusMethodNotAllowed { |
| 233 | + err := api.APIError{} |
| 234 | + DecodeJSON(t, resp, &err) |
| 235 | + assert.EqualValues(t, "Please try again later", err.Message) |
| 236 | + queue.GetManager().FlushAll(context.Background(), 5*time.Second) |
| 237 | + resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus) |
| 238 | + } |
| 239 | + |
| 240 | + expected := ctx.ExpectedCode |
| 241 | + if expected == 0 { |
| 242 | + expected = 200 |
| 243 | + } |
| 244 | + |
| 245 | + if !assert.EqualValues(t, expected, resp.Code, |
| 246 | + "Request: %s %s", req.Method, req.URL.String()) { |
| 247 | + logUnexpectedResponse(t, resp) |
230 | 248 | } |
231 | | - ctx.Session.MakeRequest(t, req, 200) |
232 | 249 | } |
233 | 250 | } |
234 | 251 |
|
|
0 commit comments