mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Consolidate boilerplate in integration tests (#1979)
This commit is contained in:
@@ -5,9 +5,7 @@
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -25,8 +23,7 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||
|
||||
// Step2: click the fork button
|
||||
htmlDoc, err := NewHtmlParser(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
htmlDoc := NewHtmlParser(t, resp.Body)
|
||||
link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
req = NewRequest(t, "GET", link)
|
||||
@@ -34,17 +31,14 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||
|
||||
// Step3: fill the form of the forking
|
||||
htmlDoc, err = NewHtmlParser(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
htmlDoc = NewHtmlParser(t, resp.Body)
|
||||
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
req = NewRequestBody(t, "POST", link,
|
||||
bytes.NewBufferString(url.Values{
|
||||
"_csrf": []string{htmlDoc.GetInputValueByName("_csrf")},
|
||||
"uid": []string{"1"},
|
||||
"repo_name": []string{"repo1"},
|
||||
}.Encode()),
|
||||
)
|
||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||
"_csrf": htmlDoc.GetCSRF(),
|
||||
"uid": "1",
|
||||
"repo_name": "repo1",
|
||||
})
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
resp = session.MakeRequest(t, req)
|
||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
||||
@@ -59,6 +53,6 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||
|
||||
func TestRepoFork(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
session := loginUser(t, "user1", "password")
|
||||
session := loginUser(t, "user1")
|
||||
testRepoFork(t, session)
|
||||
}
|
||||
|
Reference in New Issue
Block a user