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.
This commit is contained in:
parent
70aa294cc1
commit
49aea9879b
2 changed files with 42 additions and 40 deletions
|
@ -257,16 +257,23 @@ 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) {
|
||||||
|
t.Helper()
|
||||||
|
doAPIMergePullRequestForm(t, ctx, owner, repo, index, &forms.MergePullRequestForm{
|
||||||
|
MergeMessageField: "doAPIMergePullRequest Merge",
|
||||||
|
Do: string(repo_model.MergeStyleMerge),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge", owner, repo, index)
|
||||||
|
|
||||||
var req *RequestWrapper
|
var req *RequestWrapper
|
||||||
var resp *httptest.ResponseRecorder
|
var resp *httptest.ResponseRecorder
|
||||||
|
|
||||||
for i := 0; i < 6; i++ {
|
for i := 0; i < 6; i++ {
|
||||||
req = NewRequestWithJSON(t, http.MethodPost, urlStr, &forms.MergePullRequestForm{
|
req = NewRequestWithJSON(t, http.MethodPost, urlStr, merge).AddTokenAuth(ctx.Token)
|
||||||
MergeMessageField: "doAPIMergePullRequest Merge",
|
|
||||||
Do: string(repo_model.MergeStyleMerge),
|
|
||||||
}).AddTokenAuth(ctx.Token)
|
|
||||||
|
|
||||||
resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus)
|
resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus)
|
||||||
|
|
||||||
|
@ -275,7 +282,9 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
|
||||||
}
|
}
|
||||||
err := api.APIError{}
|
err := api.APIError{}
|
||||||
DecodeJSON(t, resp, &err)
|
DecodeJSON(t, resp, &err)
|
||||||
assert.EqualValues(t, "Please try again later", err.Message)
|
if err.Message != "Please try again later" {
|
||||||
|
break
|
||||||
|
}
|
||||||
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
|
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
|
||||||
<-time.After(1 * time.Second)
|
<-time.After(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
@ -289,7 +298,8 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
|
||||||
"Request: %s %s", req.Method, req.URL.String()) {
|
"Request: %s %s", req.Method, req.URL.String()) {
|
||||||
logUnexpectedResponse(t, resp)
|
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) {
|
||||||
|
|
|
@ -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…
Add table
Reference in a new issue