1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-28 13:49:13 -05:00

test(integration): refactor testPullMerge

* split into testPullMergeForm which can be called directly if
  the caller wants to specify extra parameters.
* testPullMergeForm can expect something different than StatusOK

(cherry picked from commit 20591d966e)
This commit is contained in:
Earl Warren 2024-06-01 22:18:17 +02:00
parent 9cd730a063
commit 9b17f6fd24
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -39,7 +39,20 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
type optionsPullMerge map[string]string
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string, mergeStyle repo_model.MergeStyle, deleteBranch bool) *httptest.ResponseRecorder { func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string, mergeStyle repo_model.MergeStyle, deleteBranch bool) *httptest.ResponseRecorder {
options := optionsPullMerge{
"do": string(mergeStyle),
}
if deleteBranch {
options["delete_branch_after_merge"] = "on"
}
return testPullMergeForm(t, session, http.StatusOK, user, repo, pullnum, options)
}
func testPullMergeForm(t *testing.T, session *TestSession, expectedCode int, user, repo, pullnum string, addOptions optionsPullMerge) *httptest.ResponseRecorder {
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum)) req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
resp := session.MakeRequest(t, req, http.StatusOK) resp := session.MakeRequest(t, req, http.StatusOK)
@ -48,22 +61,22 @@ func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum strin
options := map[string]string{ options := map[string]string{
"_csrf": htmlDoc.GetCSRF(), "_csrf": htmlDoc.GetCSRF(),
"do": string(mergeStyle),
} }
for k, v := range addOptions {
if deleteBranch { options[k] = v
options["delete_branch_after_merge"] = "on"
} }
req = NewRequestWithValues(t, "POST", link, options) req = NewRequestWithValues(t, "POST", link, options)
resp = session.MakeRequest(t, req, http.StatusOK) resp = session.MakeRequest(t, req, expectedCode)
respJSON := struct { if expectedCode == http.StatusOK {
Redirect string respJSON := struct {
}{} Redirect string
DecodeJSON(t, resp, &respJSON) }{}
DecodeJSON(t, resp, &respJSON)
assert.EqualValues(t, fmt.Sprintf("/%s/%s/pulls/%s", user, repo, pullnum), respJSON.Redirect) assert.EqualValues(t, fmt.Sprintf("/%s/%s/pulls/%s", user, repo, pullnum), respJSON.Redirect)
}
return resp return resp
} }