mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-15 07:09:47 +01:00
test(integration): refactor doAPIMergePullRequest
* http.StatusMethodNotAllowed can be expected: only retry if the
error message is "Please try again later"
* split into doAPIMergePullRequestForm which can be called directly if
the caller wants to specify extra parameters.
(cherry picked from commit 49aea9879b
)
This commit is contained in:
parent
68d803aae4
commit
9cd730a063
2 changed files with 42 additions and 40 deletions
|
@ -257,41 +257,51 @@ func doAPIGetPullRequest(ctx APITestContext, owner, repo string, index int64) fu
|
||||||
|
|
||||||
func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64) func(*testing.T) {
|
func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge", owner, repo, index)
|
t.Helper()
|
||||||
|
doAPIMergePullRequestForm(t, ctx, owner, repo, index, &forms.MergePullRequestForm{
|
||||||
var req *RequestWrapper
|
MergeMessageField: "doAPIMergePullRequest Merge",
|
||||||
var resp *httptest.ResponseRecorder
|
Do: string(repo_model.MergeStyleMerge),
|
||||||
|
})
|
||||||
for i := 0; i < 6; i++ {
|
|
||||||
req = NewRequestWithJSON(t, http.MethodPost, urlStr, &forms.MergePullRequestForm{
|
|
||||||
MergeMessageField: "doAPIMergePullRequest Merge",
|
|
||||||
Do: string(repo_model.MergeStyleMerge),
|
|
||||||
}).AddTokenAuth(ctx.Token)
|
|
||||||
|
|
||||||
resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus)
|
|
||||||
|
|
||||||
if resp.Code != http.StatusMethodNotAllowed {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
err := api.APIError{}
|
|
||||||
DecodeJSON(t, resp, &err)
|
|
||||||
assert.EqualValues(t, "Please try again later", err.Message)
|
|
||||||
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
|
|
||||||
<-time.After(1 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := ctx.ExpectedCode
|
|
||||||
if expected == 0 {
|
|
||||||
expected = http.StatusOK
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assert.EqualValues(t, expected, resp.Code,
|
|
||||||
"Request: %s %s", req.Method, req.URL.String()) {
|
|
||||||
logUnexpectedResponse(t, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func doAPIMergePullRequestForm(t *testing.T, ctx APITestContext, owner, repo string, index int64, merge *forms.MergePullRequestForm) *httptest.ResponseRecorder {
|
||||||
|
t.Helper()
|
||||||
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge", owner, repo, index)
|
||||||
|
|
||||||
|
var req *RequestWrapper
|
||||||
|
var resp *httptest.ResponseRecorder
|
||||||
|
|
||||||
|
for i := 0; i < 6; i++ {
|
||||||
|
req = NewRequestWithJSON(t, http.MethodPost, urlStr, merge).AddTokenAuth(ctx.Token)
|
||||||
|
|
||||||
|
resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus)
|
||||||
|
|
||||||
|
if resp.Code != http.StatusMethodNotAllowed {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
err := api.APIError{}
|
||||||
|
DecodeJSON(t, resp, &err)
|
||||||
|
if err.Message != "Please try again later" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
|
||||||
|
<-time.After(1 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := ctx.ExpectedCode
|
||||||
|
if expected == 0 {
|
||||||
|
expected = http.StatusOK
|
||||||
|
}
|
||||||
|
|
||||||
|
if !assert.EqualValues(t, expected, resp.Code,
|
||||||
|
"Request: %s %s", req.Method, req.URL.String()) {
|
||||||
|
logUnexpectedResponse(t, resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
func doAPIManuallyMergePullRequest(ctx APITestContext, owner, repo, commitID string, index int64) func(*testing.T) {
|
func doAPIManuallyMergePullRequest(ctx APITestContext, owner, repo, commitID string, index int64) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge", owner, repo, index)
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge", owner, repo, index)
|
||||||
|
|
|
@ -183,14 +183,6 @@ func doGitCheckoutBranch(dstPath string, args ...string) func(*testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doGitMerge(dstPath string, args ...string) func(*testing.T) {
|
|
||||||
return func(t *testing.T) {
|
|
||||||
t.Helper()
|
|
||||||
_, _, err := git.NewCommand(git.DefaultContext, "merge").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(&git.RunOpts{Dir: dstPath})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func doGitPull(dstPath string, args ...string) func(*testing.T) {
|
func doGitPull(dstPath string, args ...string) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
Loading…
Reference in a new issue