mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-06-02 01:59:36 +08:00
Less verbose integration tests (#2123)
* Helper functions for intergration test boilerplate
This commit is contained in:

committed by
Kim "BKC" Carlbäcker

parent
5651cc7413
commit
f1adaef458
@ -15,36 +15,32 @@ import (
|
||||
|
||||
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
|
||||
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
|
||||
resp := session.MakeRequest(t, req)
|
||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Click the little green button to craete a pull
|
||||
// Click the little green button to create a pull
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||
"_csrf": htmlDoc.GetCSRF(),
|
||||
})
|
||||
resp = session.MakeRequest(t, req)
|
||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
||||
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
|
||||
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
|
||||
resp := session.MakeRequest(t, req)
|
||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Click the little green button to craete a pull
|
||||
// Click the little green button to create a pull
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
link, exists := htmlDoc.doc.Find(".comments .merge .delete-button").Attr("data-url")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||
"_csrf": htmlDoc.GetCSRF(),
|
||||
})
|
||||
resp = session.MakeRequest(t, req)
|
||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
return resp
|
||||
}
|
||||
@ -56,10 +52,8 @@ func TestPullMerge(t *testing.T) {
|
||||
testEditFile(t, session, "user1", "repo1", "master", "README.md")
|
||||
|
||||
resp := testPullCreate(t, session, "user1", "repo1", "master")
|
||||
redirectedURL := resp.Headers["Location"]
|
||||
assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
|
||||
|
||||
elem := strings.Split(redirectedURL[0], "/")
|
||||
elem := strings.Split(RedirectURL(t, resp), "/")
|
||||
assert.EqualValues(t, "pulls", elem[3])
|
||||
testPullMerge(t, session, elem[1], elem[2], elem[4])
|
||||
}
|
||||
@ -71,10 +65,8 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
|
||||
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md")
|
||||
|
||||
resp := testPullCreate(t, session, "user1", "repo1", "feature/test")
|
||||
redirectedURL := resp.Headers["Location"]
|
||||
assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
|
||||
|
||||
elem := strings.Split(redirectedURL[0], "/")
|
||||
elem := strings.Split(RedirectURL(t, resp), "/")
|
||||
assert.EqualValues(t, "pulls", elem[3])
|
||||
testPullMerge(t, session, elem[1], elem[2], elem[4])
|
||||
|
||||
@ -92,8 +84,7 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
|
||||
|
||||
// Check branch deletion result
|
||||
req := NewRequest(t, "GET", respJSON.Redirect)
|
||||
resp = session.MakeRequest(t, req)
|
||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
resultMsg := htmlDoc.doc.Find(".ui.message>p").Text()
|
||||
|
Reference in New Issue
Block a user