mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Display URLs in integration test logs (#1924)
This commit is contained in:
		| @@ -16,8 +16,7 @@ import ( | |||||||
| func TestAPIUserReposNotLogin(t *testing.T) { | func TestAPIUserReposNotLogin(t *testing.T) { | ||||||
| 	assert.NoError(t, models.LoadFixtures()) | 	assert.NoError(t, models.LoadFixtures()) | ||||||
|  |  | ||||||
| 	req, err := http.NewRequest("GET", "/api/v1/users/user2/repos", nil) | 	req := NewRequest(t, "GET", "/api/v1/users/user2/repos") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
| @@ -25,8 +24,7 @@ func TestAPIUserReposNotLogin(t *testing.T) { | |||||||
| func TestAPISearchRepoNotLogin(t *testing.T) { | func TestAPISearchRepoNotLogin(t *testing.T) { | ||||||
| 	assert.NoError(t, models.LoadFixtures()) | 	assert.NoError(t, models.LoadFixtures()) | ||||||
|  |  | ||||||
| 	req, err := http.NewRequest("GET", "/api/v1/repos/search?q=Test", nil) | 	req := NewRequest(t, "GET", "/api/v1/repos/search?q=Test") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -25,8 +25,7 @@ func TestAPITeam(t *testing.T) { | |||||||
|  |  | ||||||
| 	session := loginUser(t, user.Name, "password") | 	session := loginUser(t, user.Name, "password") | ||||||
| 	url := fmt.Sprintf("/api/v1/teams/%d", teamUser.TeamID) | 	url := fmt.Sprintf("/api/v1/teams/%d", teamUser.TeamID) | ||||||
| 	req, err := http.NewRequest("GET", url, nil) | 	req := NewRequest(t, "GET", url) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -20,18 +20,16 @@ func TestDeleteUser(t *testing.T) { | |||||||
|  |  | ||||||
| 	session := loginUser(t, "user1", "password") | 	session := loginUser(t, "user1", "password") | ||||||
|  |  | ||||||
| 	req, err := http.NewRequest("GET", "/admin/users/8", nil) | 	req := NewRequest(t, "GET", "/admin/users/8") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| 	doc, err := NewHtmlParser(resp.Body) | 	doc, err := NewHtmlParser(resp.Body) | ||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
| 	req, err = http.NewRequest("POST", "/admin/users/8/delete", | 	req = NewRequestBody(t, "POST", "/admin/users/8/delete", | ||||||
| 		bytes.NewBufferString(url.Values{ | 		bytes.NewBufferString(url.Values{ | ||||||
| 			"_csrf": []string{doc.GetInputValueByName("_csrf")}, | 			"_csrf": []string{doc.GetInputValueByName("_csrf")}, | ||||||
| 		}.Encode())) | 		}.Encode())) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|   | |||||||
| @@ -20,8 +20,7 @@ func TestCreateFile(t *testing.T) { | |||||||
| 	session := loginUser(t, "user2", "password") | 	session := loginUser(t, "user2", "password") | ||||||
|  |  | ||||||
| 	// Request editor page | 	// Request editor page | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1/_new/master/", nil) | 	req := NewRequest(t, "GET", "/user2/repo1/_new/master/") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| @@ -31,7 +30,7 @@ func TestCreateFile(t *testing.T) { | |||||||
| 	assert.NotEmpty(t, lastCommit) | 	assert.NotEmpty(t, lastCommit) | ||||||
|  |  | ||||||
| 	// Save new file to master branch | 	// Save new file to master branch | ||||||
| 	req, err = http.NewRequest("POST", "/user2/repo1/_new/master/", | 	req = NewRequestBody(t, "POST", "/user2/repo1/_new/master/", | ||||||
| 		bytes.NewBufferString(url.Values{ | 		bytes.NewBufferString(url.Values{ | ||||||
| 			"_csrf":         []string{doc.GetInputValueByName("_csrf")}, | 			"_csrf":         []string{doc.GetInputValueByName("_csrf")}, | ||||||
| 			"last_commit":   []string{lastCommit}, | 			"last_commit":   []string{lastCommit}, | ||||||
| @@ -40,7 +39,6 @@ func TestCreateFile(t *testing.T) { | |||||||
| 			"commit_choice": []string{"direct"}, | 			"commit_choice": []string{"direct"}, | ||||||
| 		}.Encode()), | 		}.Encode()), | ||||||
| 	) | 	) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | ||||||
| @@ -52,8 +50,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { | |||||||
| 	session := loginUser(t, "user2", "password") | 	session := loginUser(t, "user2", "password") | ||||||
|  |  | ||||||
| 	// Open repository branch settings | 	// Open repository branch settings | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1/settings/branches", nil) | 	req := NewRequest(t, "GET", "/user2/repo1/settings/branches") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| @@ -61,7 +58,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { | |||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
|  |  | ||||||
| 	// Change master branch to protected | 	// Change master branch to protected | ||||||
| 	req, err = http.NewRequest("POST", "/user2/repo1/settings/branches?action=protected_branch", | 	req = NewRequestBody(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", | ||||||
| 		bytes.NewBufferString(url.Values{ | 		bytes.NewBufferString(url.Values{ | ||||||
| 			"_csrf":      []string{doc.GetInputValueByName("_csrf")}, | 			"_csrf":      []string{doc.GetInputValueByName("_csrf")}, | ||||||
| 			"branchName": []string{"master"}, | 			"branchName": []string{"master"}, | ||||||
| @@ -78,8 +75,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { | |||||||
| 	assert.EqualValues(t, flashCookie.Value, "success%3Dmaster%2BLocked%2Bsuccessfully") | 	assert.EqualValues(t, flashCookie.Value, "success%3Dmaster%2BLocked%2Bsuccessfully") | ||||||
|  |  | ||||||
| 	// Request editor page | 	// Request editor page | ||||||
| 	req, err = http.NewRequest("GET", "/user2/repo1/_new/master/", nil) | 	req = NewRequest(t, "GET", "/user2/repo1/_new/master/") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| @@ -89,7 +85,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { | |||||||
| 	assert.NotEmpty(t, lastCommit) | 	assert.NotEmpty(t, lastCommit) | ||||||
|  |  | ||||||
| 	// Save new file to master branch | 	// Save new file to master branch | ||||||
| 	req, err = http.NewRequest("POST", "/user2/repo1/_new/master/", | 	req = NewRequestBody(t, "POST", "/user2/repo1/_new/master/", | ||||||
| 		bytes.NewBufferString(url.Values{ | 		bytes.NewBufferString(url.Values{ | ||||||
| 			"_csrf":         []string{doc.GetInputValueByName("_csrf")}, | 			"_csrf":         []string{doc.GetInputValueByName("_csrf")}, | ||||||
| 			"last_commit":   []string{lastCommit}, | 			"last_commit":   []string{lastCommit}, | ||||||
| @@ -98,7 +94,6 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { | |||||||
| 			"commit_choice": []string{"direct"}, | 			"commit_choice": []string{"direct"}, | ||||||
| 		}.Encode()), | 		}.Encode()), | ||||||
| 	) | 	) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| @@ -111,8 +106,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa | |||||||
| 	newContent := "Hello, World (Edited)\n" | 	newContent := "Hello, World (Edited)\n" | ||||||
|  |  | ||||||
| 	// Get to the 'edit this file' page | 	// Get to the 'edit this file' page | ||||||
| 	req, err := http.NewRequest("GET", path.Join(user, repo, "_edit", branch, filePath), nil) | 	req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath)) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| @@ -122,7 +116,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa | |||||||
| 	assert.NotEmpty(t, lastCommit) | 	assert.NotEmpty(t, lastCommit) | ||||||
|  |  | ||||||
| 	// Submit the edits | 	// Submit the edits | ||||||
| 	req, err = http.NewRequest("POST", path.Join(user, repo, "_edit", branch, filePath), | 	req = NewRequestBody(t, "POST", path.Join(user, repo, "_edit", branch, filePath), | ||||||
| 		bytes.NewBufferString(url.Values{ | 		bytes.NewBufferString(url.Values{ | ||||||
| 			"_csrf":         []string{htmlDoc.GetInputValueByName("_csrf")}, | 			"_csrf":         []string{htmlDoc.GetInputValueByName("_csrf")}, | ||||||
| 			"last_commit":   []string{lastCommit}, | 			"last_commit":   []string{lastCommit}, | ||||||
| @@ -131,14 +125,12 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa | |||||||
| 			"commit_choice": []string{"direct"}, | 			"commit_choice": []string{"direct"}, | ||||||
| 		}.Encode()), | 		}.Encode()), | ||||||
| 	) | 	) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | ||||||
|  |  | ||||||
| 	// Verify the change | 	// Verify the change | ||||||
| 	req, err = http.NewRequest("GET", path.Join(user, repo, "raw", branch, filePath), nil) | 	req = NewRequest(t, "GET", path.Join(user, repo, "raw", branch, filePath)) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| 	assert.EqualValues(t, newContent, string(resp.Body)) | 	assert.EqualValues(t, newContent, string(resp.Body)) | ||||||
|   | |||||||
| @@ -147,22 +147,20 @@ func (s *TestSession) MakeRequest(t *testing.T, req *http.Request) *TestResponse | |||||||
| } | } | ||||||
|  |  | ||||||
| func loginUser(t *testing.T, userName, password string) *TestSession { | func loginUser(t *testing.T, userName, password string) *TestSession { | ||||||
| 	req, err := http.NewRequest("GET", "/user/login", nil) | 	req := NewRequest(t, "GET", "/user/login") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| 	doc, err := NewHtmlParser(resp.Body) | 	doc, err := NewHtmlParser(resp.Body) | ||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
|  |  | ||||||
| 	req, err = http.NewRequest("POST", "/user/login", | 	req = NewRequestBody(t, "POST", "/user/login", | ||||||
| 		bytes.NewBufferString(url.Values{ | 		bytes.NewBufferString(url.Values{ | ||||||
| 			"_csrf":     []string{doc.GetInputValueByName("_csrf")}, | 			"_csrf":     []string{doc.GetInputValueByName("_csrf")}, | ||||||
| 			"user_name": []string{userName}, | 			"user_name": []string{userName}, | ||||||
| 			"password":  []string{password}, | 			"password":  []string{password}, | ||||||
| 		}.Encode()), | 		}.Encode()), | ||||||
| 	) | 	) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||||||
| 	resp = MakeRequest(req) | 	resp = MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | ||||||
| @@ -204,6 +202,17 @@ type TestResponse struct { | |||||||
| 	Headers    http.Header | 	Headers    http.Header | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func NewRequest(t *testing.T, method, url string) *http.Request { | ||||||
|  | 	return NewRequestBody(t, method, url, nil) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func NewRequestBody(t *testing.T, method, url string, body io.Reader) *http.Request { | ||||||
|  | 	request, err := http.NewRequest(method, url, body) | ||||||
|  | 	assert.NoError(t, err) | ||||||
|  | 	request.RequestURI = url | ||||||
|  | 	return request | ||||||
|  | } | ||||||
|  |  | ||||||
| func MakeRequest(req *http.Request) *TestResponse { | func MakeRequest(req *http.Request) *TestResponse { | ||||||
| 	buffer := bytes.NewBuffer(nil) | 	buffer := bytes.NewBuffer(nil) | ||||||
| 	respWriter := &TestResponseWriter{ | 	respWriter := &TestResponseWriter{ | ||||||
|   | |||||||
| @@ -19,11 +19,10 @@ import ( | |||||||
|  |  | ||||||
| func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr, canPush bool) { | func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr, canPush bool) { | ||||||
| 	reqURL := fmt.Sprintf("/api/internal/branch/%d/%s", repoID, url.QueryEscape(branchName)) | 	reqURL := fmt.Sprintf("/api/internal/branch/%d/%s", repoID, url.QueryEscape(branchName)) | ||||||
| 	req, err := http.NewRequest("GET", reqURL, nil) | 	req := NewRequest(t, "GET", reqURL) | ||||||
| 	t.Log(reqURL) | 	t.Log(reqURL) | ||||||
| 	req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken)) | 	req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken)) | ||||||
|  |  | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	if isErr { | 	if isErr { | ||||||
| 		assert.EqualValues(t, 500, resp.HeaderCode) | 		assert.EqualValues(t, 500, resp.HeaderCode) | ||||||
|   | |||||||
| @@ -14,8 +14,7 @@ import ( | |||||||
| func TestNoLoginViewIssues(t *testing.T) { | func TestNoLoginViewIssues(t *testing.T) { | ||||||
| 	prepareTestEnv(t) | 	prepareTestEnv(t) | ||||||
|  |  | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1/issues", nil) | 	req := NewRequest(t, "GET", "/user2/repo1/issues") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
| @@ -23,8 +22,7 @@ func TestNoLoginViewIssues(t *testing.T) { | |||||||
| func TestNoLoginViewIssue(t *testing.T) { | func TestNoLoginViewIssue(t *testing.T) { | ||||||
| 	prepareTestEnv(t) | 	prepareTestEnv(t) | ||||||
|  |  | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1/issues/1", nil) | 	req := NewRequest(t, "GET", "/user2/repo1/issues/1") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,8 +15,7 @@ func TestPullCompare(t *testing.T) { | |||||||
| 	prepareTestEnv(t) | 	prepareTestEnv(t) | ||||||
|  |  | ||||||
| 	session := loginUser(t, "user2", "password") | 	session := loginUser(t, "user2", "password") | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1/pulls", nil) | 	req := NewRequest(t, "GET", "/user2/repo1/pulls") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| 	htmlDoc, err := NewHtmlParser(resp.Body) | 	htmlDoc, err := NewHtmlParser(resp.Body) | ||||||
| @@ -24,8 +23,7 @@ func TestPullCompare(t *testing.T) { | |||||||
| 	link, exists := htmlDoc.doc.Find(".navbar").Find(".ui.green.button").Attr("href") | 	link, exists := htmlDoc.doc.Find(".navbar").Find(".ui.green.button").Attr("href") | ||||||
| 	assert.True(t, exists, "The template has changed") | 	assert.True(t, exists, "The template has changed") | ||||||
|  |  | ||||||
| 	req, err = http.NewRequest("GET", link, nil) | 	req = NewRequest(t, "GET", link) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,8 +15,7 @@ func TestViewReleases(t *testing.T) { | |||||||
| 	prepareTestEnv(t) | 	prepareTestEnv(t) | ||||||
|  |  | ||||||
| 	session := loginUser(t, "user2", "password") | 	session := loginUser(t, "user2", "password") | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1/releases", nil) | 	req := NewRequest(t, "GET", "/user2/repo1/releases") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,8 +19,7 @@ func TestRepoCommits(t *testing.T) { | |||||||
| 	session := loginUser(t, "user2", "password") | 	session := loginUser(t, "user2", "password") | ||||||
|  |  | ||||||
| 	// Request repository commits page | 	// Request repository commits page | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1/commits/master", nil) | 	req := NewRequest(t, "GET", "/user2/repo1/commits/master") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| @@ -37,8 +36,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { | |||||||
| 	session := loginUser(t, "user2", "password") | 	session := loginUser(t, "user2", "password") | ||||||
|  |  | ||||||
| 	// Request repository commits page | 	// Request repository commits page | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1/commits/master", nil) | 	req := NewRequest(t, "GET", "/user2/repo1/commits/master") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| @@ -50,16 +48,14 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { | |||||||
| 	assert.NotEmpty(t, commitURL) | 	assert.NotEmpty(t, commitURL) | ||||||
|  |  | ||||||
| 	// Call API to add status for commit | 	// Call API to add status for commit | ||||||
| 	req, err = http.NewRequest("POST", "/api/v1/repos/user2/repo1/statuses/"+path.Base(commitURL), | 	req = NewRequestBody(t, "POST", "/api/v1/repos/user2/repo1/statuses/"+path.Base(commitURL), | ||||||
| 		bytes.NewBufferString("{\"state\":\""+state+"\", \"target_url\": \"http://test.ci/\", \"description\": \"\", \"context\": \"testci\"}")) | 		bytes.NewBufferString("{\"state\":\""+state+"\", \"target_url\": \"http://test.ci/\", \"description\": \"\", \"context\": \"testci\"}")) | ||||||
|  |  | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	req.Header.Add("Content-Type", "application/json") | 	req.Header.Add("Content-Type", "application/json") | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusCreated, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusCreated, resp.HeaderCode) | ||||||
|  |  | ||||||
| 	req, err = http.NewRequest("GET", "/user2/repo1/commits/master", nil) | 	req = NewRequest(t, "GET", "/user2/repo1/commits/master") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -15,14 +15,12 @@ import ( | |||||||
|  |  | ||||||
| func testRepoFork(t *testing.T, session *TestSession) { | func testRepoFork(t *testing.T, session *TestSession) { | ||||||
| 	// Step0: check the existence of the to-fork repo | 	// Step0: check the existence of the to-fork repo | ||||||
| 	req, err := http.NewRequest("GET", "/user1/repo1", nil) | 	req := NewRequest(t, "GET", "/user1/repo1") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := session.MakeRequest(t, req) | 	resp := session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode) | ||||||
|  |  | ||||||
| 	// Step1: go to the main page of repo | 	// Step1: go to the main page of repo | ||||||
| 	req, err = http.NewRequest("GET", "/user2/repo1", nil) | 	req = NewRequest(t, "GET", "/user2/repo1") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| @@ -31,8 +29,7 @@ func testRepoFork(t *testing.T, session *TestSession) { | |||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
| 	link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href") | 	link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href") | ||||||
| 	assert.True(t, exists, "The template has changed") | 	assert.True(t, exists, "The template has changed") | ||||||
| 	req, err = http.NewRequest("GET", link, nil) | 	req = NewRequest(t, "GET", link) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
|  |  | ||||||
| @@ -41,21 +38,19 @@ func testRepoFork(t *testing.T, session *TestSession) { | |||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
| 	link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action") | 	link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action") | ||||||
| 	assert.True(t, exists, "The template has changed") | 	assert.True(t, exists, "The template has changed") | ||||||
| 	req, err = http.NewRequest("POST", link, | 	req = NewRequestBody(t, "POST", link, | ||||||
| 		bytes.NewBufferString(url.Values{ | 		bytes.NewBufferString(url.Values{ | ||||||
| 			"_csrf":     []string{htmlDoc.GetInputValueByName("_csrf")}, | 			"_csrf":     []string{htmlDoc.GetInputValueByName("_csrf")}, | ||||||
| 			"uid":       []string{"1"}, | 			"uid":       []string{"1"}, | ||||||
| 			"repo_name": []string{"repo1"}, | 			"repo_name": []string{"repo1"}, | ||||||
| 		}.Encode()), | 		}.Encode()), | ||||||
| 	) | 	) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | ||||||
|  |  | ||||||
| 	// Step4: check the existence of the forked repo | 	// Step4: check the existence of the forked repo | ||||||
| 	req, err = http.NewRequest("GET", "/user1/repo1", nil) | 	req = NewRequest(t, "GET", "/user1/repo1") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp = session.MakeRequest(t, req) | 	resp = session.MakeRequest(t, req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,8 +14,7 @@ import ( | |||||||
| func TestViewRepo(t *testing.T) { | func TestViewRepo(t *testing.T) { | ||||||
| 	prepareTestEnv(t) | 	prepareTestEnv(t) | ||||||
|  |  | ||||||
| 	req, err := http.NewRequest("GET", "/user2/repo1", nil) | 	req := NewRequest(t, "GET", "/user2/repo1") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,7 +20,7 @@ func TestSignup(t *testing.T) { | |||||||
|  |  | ||||||
| 	setting.Service.EnableCaptcha = false | 	setting.Service.EnableCaptcha = false | ||||||
|  |  | ||||||
| 	req, err := http.NewRequest("POST", "/user/sign_up", | 	req := NewRequestBody(t, "POST", "/user/sign_up", | ||||||
| 		bytes.NewBufferString(url.Values{ | 		bytes.NewBufferString(url.Values{ | ||||||
| 			"user_name": []string{"exampleUser"}, | 			"user_name": []string{"exampleUser"}, | ||||||
| 			"email":     []string{"exampleUser@example.com"}, | 			"email":     []string{"exampleUser@example.com"}, | ||||||
| @@ -28,14 +28,12 @@ func TestSignup(t *testing.T) { | |||||||
| 			"retype":    []string{"examplePassword"}, | 			"retype":    []string{"examplePassword"}, | ||||||
| 		}.Encode()), | 		}.Encode()), | ||||||
| 	) | 	) | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | 	req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusFound, resp.HeaderCode) | ||||||
|  |  | ||||||
| 	// should be able to view new user's page | 	// should be able to view new user's page | ||||||
| 	req, err = http.NewRequest("GET", "/exampleUser", nil) | 	req = NewRequest(t, "GET", "/exampleUser") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp = MakeRequest(req) | 	resp = MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,8 +14,7 @@ import ( | |||||||
| func TestViewUser(t *testing.T) { | func TestViewUser(t *testing.T) { | ||||||
| 	prepareTestEnv(t) | 	prepareTestEnv(t) | ||||||
|  |  | ||||||
| 	req, err := http.NewRequest("GET", "/user2", nil) | 	req := NewRequest(t, "GET", "/user2") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
| 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,8 +20,7 @@ func TestVersion(t *testing.T) { | |||||||
| 	prepareTestEnv(t) | 	prepareTestEnv(t) | ||||||
|  |  | ||||||
| 	setting.AppVer = "1.1.0+dev" | 	setting.AppVer = "1.1.0+dev" | ||||||
| 	req, err := http.NewRequest("GET", "/api/v1/version", nil) | 	req := NewRequest(t, "GET", "/api/v1/version") | ||||||
| 	assert.NoError(t, err) |  | ||||||
| 	resp := MakeRequest(req) | 	resp := MakeRequest(req) | ||||||
|  |  | ||||||
| 	var version gitea.ServerVersion | 	var version gitea.ServerVersion | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user