mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Use httptest in integration tests (#3080)
This commit is contained in:
		@@ -6,6 +6,7 @@ package integrations
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/http/httptest"
 | 
			
		||||
	"path"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
@@ -72,7 +73,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	resp = session.MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
	// Check body for error message
 | 
			
		||||
	assert.Contains(t, string(resp.Body), "Can not commit to protected branch 'master'.")
 | 
			
		||||
	assert.Contains(t, resp.Body.String(), "Can not commit to protected branch 'master'.")
 | 
			
		||||
 | 
			
		||||
	// remove the protected branch
 | 
			
		||||
	csrf = GetCSRF(t, session, "/user2/repo1/settings/branches")
 | 
			
		||||
@@ -89,7 +90,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath, newContent string) *TestResponse {
 | 
			
		||||
func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath, newContent string) *httptest.ResponseRecorder {
 | 
			
		||||
	// Get to the 'edit this file' page
 | 
			
		||||
	req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
 | 
			
		||||
	resp := session.MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
@@ -113,12 +114,12 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
 | 
			
		||||
	// Verify the change
 | 
			
		||||
	req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", branch, filePath))
 | 
			
		||||
	resp = session.MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
	assert.EqualValues(t, newContent, string(resp.Body))
 | 
			
		||||
	assert.EqualValues(t, newContent, resp.Body.String())
 | 
			
		||||
 | 
			
		||||
	return resp
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) *TestResponse {
 | 
			
		||||
func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) *httptest.ResponseRecorder {
 | 
			
		||||
 | 
			
		||||
	// Get to the 'edit this file' page
 | 
			
		||||
	req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
 | 
			
		||||
@@ -144,7 +145,7 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
 | 
			
		||||
	// Verify the change
 | 
			
		||||
	req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", targetBranch, filePath))
 | 
			
		||||
	resp = session.MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
	assert.EqualValues(t, newContent, string(resp.Body))
 | 
			
		||||
	assert.EqualValues(t, newContent, resp.Body.String())
 | 
			
		||||
 | 
			
		||||
	return resp
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user