Browse Source

Use httptest in integration tests (#3080)

Ethan Koenig 1 year ago
parent
commit
e59adcde65

+ 2 - 2
integrations/api_branch_test.go

@@ -20,10 +20,10 @@ func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
20 20
 	req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s", branchName)
21 21
 	resp := session.MakeRequest(t, req, NoExpectedStatus)
22 22
 	if !exists {
23
-		assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
23
+		assert.EqualValues(t, http.StatusNotFound, resp.Code)
24 24
 		return
25 25
 	}
26
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
26
+	assert.EqualValues(t, http.StatusOK, resp.Code)
27 27
 	var branch api.Branch
28 28
 	DecodeJSON(t, resp, &branch)
29 29
 	assert.EqualValues(t, branchName, branch.Name)

+ 36 - 33
integrations/api_gpg_keys_test.go

@@ -6,27 +6,30 @@ package integrations
6 6
 
7 7
 import (
8 8
 	"net/http"
9
+	"net/http/httptest"
9 10
 	"strconv"
10 11
 	"testing"
11 12
 
12
-	"github.com/stretchr/testify/assert"
13
-
14 13
 	api "code.gitea.io/sdk/gitea"
14
+
15
+	"github.com/stretchr/testify/assert"
15 16
 )
16 17
 
18
+type makeRequestFunc func(testing.TB, *http.Request, int) *httptest.ResponseRecorder
19
+
17 20
 func TestGPGKeys(t *testing.T) {
18 21
 	prepareTestEnv(t)
19 22
 	session := loginUser(t, "user2")
20 23
 
21 24
 	tt := []struct {
22
-		name       string
23
-		reqBuilder func(testing.TB, *http.Request, int) *TestResponse
24
-		results    []int
25
+		name        string
26
+		makeRequest makeRequestFunc
27
+		results     []int
25 28
 	}{
26
-		{name: "NoLogin", reqBuilder: MakeRequest,
29
+		{name: "NoLogin", makeRequest: MakeRequest,
27 30
 			results: []int{http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized},
28 31
 		},
29
-		{name: "LoggedAsUser2", reqBuilder: session.MakeRequest,
32
+		{name: "LoggedAsUser2", makeRequest: session.MakeRequest,
30 33
 			results: []int{http.StatusOK, http.StatusOK, http.StatusNotFound, http.StatusNoContent, http.StatusInternalServerError, http.StatusInternalServerError, http.StatusCreated, http.StatusCreated}},
31 34
 	}
32 35
 
@@ -35,29 +38,29 @@ func TestGPGKeys(t *testing.T) {
35 38
 		//Basic test on result code
36 39
 		t.Run(tc.name, func(t *testing.T) {
37 40
 			t.Run("ViewOwnGPGKeys", func(t *testing.T) {
38
-				testViewOwnGPGKeys(t, tc.reqBuilder, tc.results[0])
41
+				testViewOwnGPGKeys(t, tc.makeRequest, tc.results[0])
39 42
 			})
40 43
 			t.Run("ViewGPGKeys", func(t *testing.T) {
41
-				testViewGPGKeys(t, tc.reqBuilder, tc.results[1])
44
+				testViewGPGKeys(t, tc.makeRequest, tc.results[1])
42 45
 			})
43 46
 			t.Run("GetGPGKey", func(t *testing.T) {
44
-				testGetGPGKey(t, tc.reqBuilder, tc.results[2])
47
+				testGetGPGKey(t, tc.makeRequest, tc.results[2])
45 48
 			})
46 49
 			t.Run("DeleteGPGKey", func(t *testing.T) {
47
-				testDeleteGPGKey(t, tc.reqBuilder, tc.results[3])
50
+				testDeleteGPGKey(t, tc.makeRequest, tc.results[3])
48 51
 			})
49 52
 
50 53
 			t.Run("CreateInvalidGPGKey", func(t *testing.T) {
51
-				testCreateInvalidGPGKey(t, tc.reqBuilder, tc.results[4])
54
+				testCreateInvalidGPGKey(t, tc.makeRequest, tc.results[4])
52 55
 			})
53 56
 			t.Run("CreateNoneRegistredEmailGPGKey", func(t *testing.T) {
54
-				testCreateNoneRegistredEmailGPGKey(t, tc.reqBuilder, tc.results[5])
57
+				testCreateNoneRegistredEmailGPGKey(t, tc.makeRequest, tc.results[5])
55 58
 			})
56 59
 			t.Run("CreateValidGPGKey", func(t *testing.T) {
57
-				testCreateValidGPGKey(t, tc.reqBuilder, tc.results[6])
60
+				testCreateValidGPGKey(t, tc.makeRequest, tc.results[6])
58 61
 			})
59 62
 			t.Run("CreateValidSecondaryEmailGPGKey", func(t *testing.T) {
60
-				testCreateValidSecondaryEmailGPGKey(t, tc.reqBuilder, tc.results[7])
63
+				testCreateValidSecondaryEmailGPGKey(t, tc.makeRequest, tc.results[7])
61 64
 			})
62 65
 		})
63 66
 	}
@@ -140,39 +143,39 @@ func TestGPGKeys(t *testing.T) {
140 143
 	})
141 144
 }
142 145
 
143
-func testViewOwnGPGKeys(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int) {
146
+func testViewOwnGPGKeys(t *testing.T, makeRequest makeRequestFunc, expected int) {
144 147
 	req := NewRequest(t, "GET", "/api/v1/user/gpg_keys")
145
-	reqBuilder(t, req, expected)
148
+	makeRequest(t, req, expected)
146 149
 }
147 150
 
148
-func testViewGPGKeys(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int) {
151
+func testViewGPGKeys(t *testing.T, makeRequest makeRequestFunc, expected int) {
149 152
 	req := NewRequest(t, "GET", "/api/v1/users/user2/gpg_keys")
150
-	reqBuilder(t, req, expected)
153
+	makeRequest(t, req, expected)
151 154
 }
152 155
 
153
-func testGetGPGKey(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int) {
156
+func testGetGPGKey(t *testing.T, makeRequest makeRequestFunc, expected int) {
154 157
 	req := NewRequest(t, "GET", "/api/v1/user/gpg_keys/1")
155
-	reqBuilder(t, req, expected)
158
+	makeRequest(t, req, expected)
156 159
 }
157 160
 
158
-func testDeleteGPGKey(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int) {
161
+func testDeleteGPGKey(t *testing.T, makeRequest makeRequestFunc, expected int) {
159 162
 	req := NewRequest(t, "DELETE", "/api/v1/user/gpg_keys/1")
160
-	reqBuilder(t, req, expected)
163
+	makeRequest(t, req, expected)
161 164
 }
162 165
 
163
-func testCreateGPGKey(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int, publicKey string) {
166
+func testCreateGPGKey(t *testing.T, makeRequest makeRequestFunc, expected int, publicKey string) {
164 167
 	req := NewRequestWithJSON(t, "POST", "/api/v1/user/gpg_keys", api.CreateGPGKeyOption{
165 168
 		ArmoredKey: publicKey,
166 169
 	})
167
-	reqBuilder(t, req, expected)
170
+	makeRequest(t, req, expected)
168 171
 }
169 172
 
170
-func testCreateInvalidGPGKey(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int) {
171
-	testCreateGPGKey(t, reqBuilder, expected, "invalid_key")
173
+func testCreateInvalidGPGKey(t *testing.T, makeRequest makeRequestFunc, expected int) {
174
+	testCreateGPGKey(t, makeRequest, expected, "invalid_key")
172 175
 }
173 176
 
174
-func testCreateNoneRegistredEmailGPGKey(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int) {
175
-	testCreateGPGKey(t, reqBuilder, expected, `-----BEGIN PGP PUBLIC KEY BLOCK-----
177
+func testCreateNoneRegistredEmailGPGKey(t *testing.T, makeRequest makeRequestFunc, expected int) {
178
+	testCreateGPGKey(t, makeRequest, expected, `-----BEGIN PGP PUBLIC KEY BLOCK-----
176 179
 
177 180
 mQENBFmGUygBCACjCNbKvMGgp0fd5vyFW9olE1CLCSyyF9gQN2hSuzmZLuAZF2Kh
178 181
 dCMCG2T1UwzUB/yWUFWJ2BtCwSjuaRv+cGohqEy6bhEBV90peGA33lHfjx7wP25O
@@ -191,9 +194,9 @@ INx/MmBfmtCq05FqNclvU+sj2R3N1JJOtBOjZrJHQbJhzoILou8AkxeX1A+q9OAz
191 194
 -----END PGP PUBLIC KEY BLOCK-----`)
192 195
 }
193 196
 
194
-func testCreateValidGPGKey(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int) {
197
+func testCreateValidGPGKey(t *testing.T, makeRequest makeRequestFunc, expected int) {
195 198
 	//User2 <user2@example.com> //primary & activated
196
-	testCreateGPGKey(t, reqBuilder, expected, `-----BEGIN PGP PUBLIC KEY BLOCK-----
199
+	testCreateGPGKey(t, makeRequest, expected, `-----BEGIN PGP PUBLIC KEY BLOCK-----
197 200
 
198 201
 mQENBFmGVsMBCACuxgZ7W7rI9xN08Y4M7B8yx/6/I4Slm94+wXf8YNRvAyqj30dW
199 202
 VJhyBcnfNRDLKSQp5o/hhfDkCgdqBjLa1PnHlGS3PXJc0hP/FyYPD2BFvNMPpCYS
@@ -225,9 +228,9 @@ uy6MA3VSB99SK9ducGmE1Jv8mcziREroz2TEGr0zPs6h
225 228
 -----END PGP PUBLIC KEY BLOCK-----`)
226 229
 }
227 230
 
228
-func testCreateValidSecondaryEmailGPGKey(t *testing.T, reqBuilder func(testing.TB, *http.Request, int) *TestResponse, expected int) {
231
+func testCreateValidSecondaryEmailGPGKey(t *testing.T, makeRequest makeRequestFunc, expected int) {
229 232
 	//User2 <user21@example.com> //secondary and not activated
230
-	testCreateGPGKey(t, reqBuilder, expected, `-----BEGIN PGP PUBLIC KEY BLOCK-----
233
+	testCreateGPGKey(t, makeRequest, expected, `-----BEGIN PGP PUBLIC KEY BLOCK-----
231 234
 
232 235
 mQENBFmGWN4BCAC18V4tVGO65VLCV7p14FuXJlUtZ5CuYMvgEkcOqrvRaBSW9ao4
233 236
 PGESOhJpfWpnW3QgJniYndLzPpsmdHEclEER6aZjiNgReWPOjHD5tykWocZAJqXD

+ 4 - 4
integrations/branches_test.go

@@ -59,9 +59,8 @@ func branchAction(t *testing.T, button string) (*HTMLDoc, string) {
59 59
 	link, exists := htmlDoc.doc.Find(button).Attr("data-url")
60 60
 	assert.True(t, exists, "The template has changed")
61 61
 
62
-	htmlDoc = NewHTMLParser(t, resp.Body)
63 62
 	req = NewRequestWithValues(t, "POST", link, map[string]string{
64
-		"_csrf": getCsrf(htmlDoc.doc),
63
+		"_csrf": getCsrf(t, htmlDoc.doc),
65 64
 	})
66 65
 	resp = session.MakeRequest(t, req, http.StatusOK)
67 66
 
@@ -73,7 +72,8 @@ func branchAction(t *testing.T, button string) (*HTMLDoc, string) {
73 72
 	return NewHTMLParser(t, resp.Body), url.Query()["name"][0]
74 73
 }
75 74
 
76
-func getCsrf(doc *goquery.Document) string {
77
-	csrf, _ := doc.Find("meta[name=\"_csrf\"]").Attr("content")
75
+func getCsrf(t *testing.T, doc *goquery.Document) string {
76
+	csrf, exists := doc.Find("meta[name=\"_csrf\"]").Attr("content")
77
+	assert.True(t, exists)
78 78
 	return csrf
79 79
 }

+ 6 - 5
integrations/editor_test.go

@@ -6,6 +6,7 @@ package integrations
6 6
 
7 7
 import (
8 8
 	"net/http"
9
+	"net/http/httptest"
9 10
 	"path"
10 11
 	"testing"
11 12
 
@@ -72,7 +73,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
72 73
 
73 74
 	resp = session.MakeRequest(t, req, http.StatusOK)
74 75
 	// Check body for error message
75
-	assert.Contains(t, string(resp.Body), "Can not commit to protected branch &#39;master&#39;.")
76
+	assert.Contains(t, resp.Body.String(), "Can not commit to protected branch &#39;master&#39;.")
76 77
 
77 78
 	// remove the protected branch
78 79
 	csrf = GetCSRF(t, session, "/user2/repo1/settings/branches")
@@ -89,7 +90,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
89 90
 
90 91
 }
91 92
 
92
-func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath, newContent string) *TestResponse {
93
+func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath, newContent string) *httptest.ResponseRecorder {
93 94
 	// Get to the 'edit this file' page
94 95
 	req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
95 96
 	resp := session.MakeRequest(t, req, http.StatusOK)
@@ -113,12 +114,12 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
113 114
 	// Verify the change
114 115
 	req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", branch, filePath))
115 116
 	resp = session.MakeRequest(t, req, http.StatusOK)
116
-	assert.EqualValues(t, newContent, string(resp.Body))
117
+	assert.EqualValues(t, newContent, resp.Body.String())
117 118
 
118 119
 	return resp
119 120
 }
120 121
 
121
-func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) *TestResponse {
122
+func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) *httptest.ResponseRecorder {
122 123
 
123 124
 	// Get to the 'edit this file' page
124 125
 	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
144 145
 	// Verify the change
145 146
 	req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", targetBranch, filePath))
146 147
 	resp = session.MakeRequest(t, req, http.StatusOK)
147
-	assert.EqualValues(t, newContent, string(resp.Body))
148
+	assert.EqualValues(t, newContent, resp.Body.String())
148 149
 
149 150
 	return resp
150 151
 }

+ 2 - 2
integrations/html_helper.go

@@ -18,8 +18,8 @@ type HTMLDoc struct {
18 18
 }
19 19
 
20 20
 // NewHTMLParser parse html file
21
-func NewHTMLParser(t testing.TB, content []byte) *HTMLDoc {
22
-	doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
21
+func NewHTMLParser(t testing.TB, body *bytes.Buffer) *HTMLDoc {
22
+	doc, err := goquery.NewDocumentFromReader(body)
23 23
 	assert.NoError(t, err)
24 24
 	return &HTMLDoc{doc: doc}
25 25
 }

+ 13 - 44
integrations/integration_test.go

@@ -13,6 +13,7 @@ import (
13 13
 	"log"
14 14
 	"net/http"
15 15
 	"net/http/cookiejar"
16
+	"net/http/httptest"
16 17
 	"net/url"
17 18
 	"os"
18 19
 	"path"
@@ -158,7 +159,7 @@ func (s *TestSession) GetCookie(name string) *http.Cookie {
158 159
 	return nil
159 160
 }
160 161
 
161
-func (s *TestSession) MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *TestResponse {
162
+func (s *TestSession) MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.ResponseRecorder {
162 163
 	baseURL, err := url.Parse(setting.AppURL)
163 164
 	assert.NoError(t, err)
164 165
 	for _, c := range s.jar.Cookies(baseURL) {
@@ -167,7 +168,7 @@ func (s *TestSession) MakeRequest(t testing.TB, req *http.Request, expectedStatu
167 168
 	resp := MakeRequest(t, req, expectedStatus)
168 169
 
169 170
 	ch := http.Header{}
170
-	ch.Add("Cookie", strings.Join(resp.Headers["Set-Cookie"], ";"))
171
+	ch.Add("Cookie", strings.Join(resp.HeaderMap["Set-Cookie"], ";"))
171 172
 	cr := http.Request{Header: ch}
172 173
 	s.jar.SetCookies(baseURL, cr.Cookies())
173 174
 
@@ -207,7 +208,7 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession
207 208
 	resp = MakeRequest(t, req, http.StatusFound)
208 209
 
209 210
 	ch := http.Header{}
210
-	ch.Add("Cookie", strings.Join(resp.Headers["Set-Cookie"], ";"))
211
+	ch.Add("Cookie", strings.Join(resp.HeaderMap["Set-Cookie"], ";"))
211 212
 	cr := http.Request{Header: ch}
212 213
 
213 214
 	session := emptyTestSession(t)
@@ -219,30 +220,6 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession
219 220
 	return session
220 221
 }
221 222
 
222
-type TestResponseWriter struct {
223
-	HeaderCode int
224
-	Writer     io.Writer
225
-	Headers    http.Header
226
-}
227
-
228
-func (w *TestResponseWriter) Header() http.Header {
229
-	return w.Headers
230
-}
231
-
232
-func (w *TestResponseWriter) Write(b []byte) (int, error) {
233
-	return w.Writer.Write(b)
234
-}
235
-
236
-func (w *TestResponseWriter) WriteHeader(n int) {
237
-	w.HeaderCode = n
238
-}
239
-
240
-type TestResponse struct {
241
-	HeaderCode int
242
-	Body       []byte
243
-	Headers    http.Header
244
-}
245
-
246 223
 func NewRequest(t testing.TB, method, urlStr string) *http.Request {
247 224
 	return NewRequestWithBody(t, method, urlStr, nil)
248 225
 }
@@ -278,26 +255,18 @@ func NewRequestWithBody(t testing.TB, method, urlStr string, body io.Reader) *ht
278 255
 
279 256
 const NoExpectedStatus = -1
280 257
 
281
-func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *TestResponse {
282
-	buffer := bytes.NewBuffer(nil)
283
-	respWriter := &TestResponseWriter{
284
-		Writer:  buffer,
285
-		Headers: make(map[string][]string),
286
-	}
287
-	mac.ServeHTTP(respWriter, req)
258
+func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.ResponseRecorder {
259
+	recorder := httptest.NewRecorder()
260
+	mac.ServeHTTP(recorder, req)
288 261
 	if expectedStatus != NoExpectedStatus {
289
-		assert.EqualValues(t, expectedStatus, respWriter.HeaderCode,
262
+		assert.EqualValues(t, expectedStatus, recorder.Code,
290 263
 			"Request: %s %s", req.Method, req.URL.String())
291 264
 	}
292
-	return &TestResponse{
293
-		HeaderCode: respWriter.HeaderCode,
294
-		Body:       buffer.Bytes(),
295
-		Headers:    respWriter.Headers,
296
-	}
265
+	return recorder
297 266
 }
298 267
 
299
-func DecodeJSON(t testing.TB, resp *TestResponse, v interface{}) {
300
-	decoder := json.NewDecoder(bytes.NewBuffer(resp.Body))
268
+func DecodeJSON(t testing.TB, resp *httptest.ResponseRecorder, v interface{}) {
269
+	decoder := json.NewDecoder(resp.Body)
301 270
 	assert.NoError(t, decoder.Decode(v))
302 271
 }
303 272
 
@@ -308,8 +277,8 @@ func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
308 277
 	return doc.GetCSRF()
309 278
 }
310 279
 
311
-func RedirectURL(t testing.TB, resp *TestResponse) string {
312
-	urlSlice := resp.Headers["Location"]
280
+func RedirectURL(t testing.TB, resp *httptest.ResponseRecorder) string {
281
+	urlSlice := resp.HeaderMap["Location"]
313 282
 	assert.NotEmpty(t, urlSlice, "No redirect URL founds")
314 283
 	return urlSlice[0]
315 284
 }

+ 4 - 4
integrations/internal_test.go

@@ -25,12 +25,12 @@ func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr,
25 25
 
26 26
 	resp := MakeRequest(t, req, NoExpectedStatus)
27 27
 	if isErr {
28
-		assert.EqualValues(t, http.StatusInternalServerError, resp.HeaderCode)
28
+		assert.EqualValues(t, http.StatusInternalServerError, resp.Code)
29 29
 	} else {
30
-		assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
30
+		assert.EqualValues(t, http.StatusOK, resp.Code)
31 31
 		var branch models.ProtectedBranch
32
-		t.Log(string(resp.Body))
33
-		assert.NoError(t, json.Unmarshal(resp.Body, &branch))
32
+		t.Log(resp.Body.String())
33
+		assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &branch))
34 34
 		assert.Equal(t, canPush, !branch.IsProtected())
35 35
 	}
36 36
 }

+ 1 - 1
integrations/pull_compare_test.go

@@ -23,5 +23,5 @@ func TestPullCompare(t *testing.T) {
23 23
 
24 24
 	req = NewRequest(t, "GET", link)
25 25
 	resp = session.MakeRequest(t, req, http.StatusOK)
26
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
26
+	assert.EqualValues(t, http.StatusOK, resp.Code)
27 27
 }

+ 2 - 1
integrations/pull_create_test.go

@@ -6,6 +6,7 @@ package integrations
6 6
 
7 7
 import (
8 8
 	"net/http"
9
+	"net/http/httptest"
9 10
 	"path"
10 11
 	"strings"
11 12
 	"testing"
@@ -13,7 +14,7 @@ import (
13 14
 	"github.com/stretchr/testify/assert"
14 15
 )
15 16
 
16
-func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *TestResponse {
17
+func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *httptest.ResponseRecorder {
17 18
 	req := NewRequest(t, "GET", path.Join(user, repo))
18 19
 	resp := session.MakeRequest(t, req, http.StatusOK)
19 20
 

+ 3 - 2
integrations/pull_merge_test.go

@@ -6,6 +6,7 @@ package integrations
6 6
 
7 7
 import (
8 8
 	"net/http"
9
+	"net/http/httptest"
9 10
 	"path"
10 11
 	"strings"
11 12
 	"testing"
@@ -13,7 +14,7 @@ import (
13 14
 	"github.com/stretchr/testify/assert"
14 15
 )
15 16
 
16
-func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
17
+func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *httptest.ResponseRecorder {
17 18
 	req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
18 19
 	resp := session.MakeRequest(t, req, http.StatusOK)
19 20
 
@@ -29,7 +30,7 @@ func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum strin
29 30
 	return resp
30 31
 }
31 32
 
32
-func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
33
+func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum string) *httptest.ResponseRecorder {
33 34
 	req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
34 35
 	resp := session.MakeRequest(t, req, http.StatusOK)
35 36
 

+ 2 - 1
integrations/repo_fork_test.go

@@ -7,6 +7,7 @@ package integrations
7 7
 import (
8 8
 	"fmt"
9 9
 	"net/http"
10
+	"net/http/httptest"
10 11
 	"testing"
11 12
 
12 13
 	"code.gitea.io/gitea/models"
@@ -14,7 +15,7 @@ import (
14 15
 	"github.com/stretchr/testify/assert"
15 16
 )
16 17
 
17
-func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *TestResponse {
18
+func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *httptest.ResponseRecorder {
18 19
 	forkOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: forkOwnerName}).(*models.User)
19 20
 
20 21
 	// Step0: check the existence of the to-fork repo

+ 2 - 1
integrations/repo_migrate_test.go

@@ -6,12 +6,13 @@ package integrations
6 6
 
7 7
 import (
8 8
 	"net/http"
9
+	"net/http/httptest"
9 10
 	"testing"
10 11
 
11 12
 	"github.com/stretchr/testify/assert"
12 13
 )
13 14
 
14
-func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName string) *TestResponse {
15
+func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName string) *httptest.ResponseRecorder {
15 16
 	req := NewRequest(t, "GET", "/repo/migrate")
16 17
 	resp := session.MakeRequest(t, req, http.StatusOK)
17 18
 	htmlDoc := NewHTMLParser(t, resp.Body)