Attempt to handle unready PR in tests (#13305)
Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
7974b34183
commit
66dcf10845
1 changed files with 21 additions and 4 deletions
|
@ -5,14 +5,17 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
|
"code.gitea.io/gitea/modules/queue"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -225,11 +228,25 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
|
||||||
Do: string(models.MergeStyleMerge),
|
Do: string(models.MergeStyleMerge),
|
||||||
})
|
})
|
||||||
|
|
||||||
if ctx.ExpectedCode != 0 {
|
resp := ctx.Session.MakeRequest(t, req, NoExpectedStatus)
|
||||||
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)
|
|
||||||
return
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue