Browse Source

Less verbose integration tests (#2123)

* Helper functions for intergration test boilerplate
Ethan Koenig 1 year ago
parent
commit
f1adaef458

+ 1 - 1
integrations/api_branch_test.go

@@ -18,7 +18,7 @@ func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
18 18
 
19 19
 	session := loginUser(t, "user2")
20 20
 	req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s", branchName)
21
-	resp := session.MakeRequest(t, req)
21
+	resp := session.MakeRequest(t, req, NoExpectedStatus)
22 22
 	if !exists {
23 23
 		assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
24 24
 		return

+ 1 - 2
integrations/api_comment_test.go

@@ -26,8 +26,7 @@ func TestAPIListComments(t *testing.T) {
26 26
 	session := loginUser(t, repoOwner.Name)
27 27
 	req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments",
28 28
 		repoOwner.Name, repo.Name, issue.Index)
29
-	resp := session.MakeRequest(t, req)
30
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
29
+	resp := session.MakeRequest(t, req, http.StatusOK)
31 30
 
32 31
 	var comments []*api.Comment
33 32
 	DecodeJSON(t, resp, &comments)

+ 2 - 4
integrations/api_issue_label_test.go

@@ -29,8 +29,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
29 29
 		Labels: []int64{label.ID},
30 30
 	})
31 31
 	session := loginUser(t, owner.Name)
32
-	resp := session.MakeRequest(t, req)
33
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
32
+	resp := session.MakeRequest(t, req, http.StatusOK)
34 33
 	var apiLabels []*api.Label
35 34
 	DecodeJSON(t, resp, &apiLabels)
36 35
 	assert.Len(t, apiLabels, models.GetCount(t, &models.IssueLabel{IssueID: issue.ID}))
@@ -52,8 +51,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
52 51
 		Labels: []int64{label.ID},
53 52
 	})
54 53
 	session := loginUser(t, owner.Name)
55
-	resp := session.MakeRequest(t, req)
56
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
54
+	resp := session.MakeRequest(t, req, http.StatusOK)
57 55
 	var apiLabels []*api.Label
58 56
 	DecodeJSON(t, resp, &apiLabels)
59 57
 	assert.Len(t, apiLabels, 1)

+ 2 - 4
integrations/api_issue_test.go

@@ -24,8 +24,7 @@ func TestAPIListIssues(t *testing.T) {
24 24
 	session := loginUser(t, owner.Name)
25 25
 	req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all",
26 26
 		owner.Name, repo.Name)
27
-	resp := session.MakeRequest(t, req)
28
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
27
+	resp := session.MakeRequest(t, req, http.StatusOK)
29 28
 	var apiIssues []*api.Issue
30 29
 	DecodeJSON(t, resp, &apiIssues)
31 30
 	assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID}))
@@ -49,8 +48,7 @@ func TestAPICreateIssue(t *testing.T) {
49 48
 		Title:    title,
50 49
 		Assignee: owner.Name,
51 50
 	})
52
-	resp := session.MakeRequest(t, req)
53
-	assert.EqualValues(t, http.StatusCreated, resp.HeaderCode)
51
+	resp := session.MakeRequest(t, req, http.StatusCreated)
54 52
 	var apiIssue api.Issue
55 53
 	DecodeJSON(t, resp, &apiIssue)
56 54
 	assert.Equal(t, apiIssue.Body, body)

+ 1 - 2
integrations/api_pull_test.go

@@ -21,8 +21,7 @@ func TestAPIViewPulls(t *testing.T) {
21 21
 
22 22
 	session := loginUser(t, "user2")
23 23
 	req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls?state=all", owner.Name, repo.Name)
24
-	resp := session.MakeRequest(t, req)
25
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
24
+	resp := session.MakeRequest(t, req, http.StatusOK)
26 25
 
27 26
 	var pulls []*api.PullRequest
28 27
 	DecodeJSON(t, resp, &pulls)

+ 2 - 6
integrations/api_repo_test.go

@@ -7,22 +7,18 @@ package integrations
7 7
 import (
8 8
 	"net/http"
9 9
 	"testing"
10
-
11
-	"github.com/stretchr/testify/assert"
12 10
 )
13 11
 
14 12
 func TestAPIUserReposNotLogin(t *testing.T) {
15 13
 	prepareTestEnv(t)
16 14
 
17 15
 	req := NewRequest(t, "GET", "/api/v1/users/user2/repos")
18
-	resp := MakeRequest(req)
19
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
16
+	MakeRequest(t, req, http.StatusOK)
20 17
 }
21 18
 
22 19
 func TestAPISearchRepoNotLogin(t *testing.T) {
23 20
 	prepareTestEnv(t)
24 21
 
25 22
 	req := NewRequest(t, "GET", "/api/v1/repos/search?q=Test")
26
-	resp := MakeRequest(req)
27
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
23
+	MakeRequest(t, req, http.StatusOK)
28 24
 }

+ 1 - 2
integrations/api_team_test.go

@@ -22,8 +22,7 @@ func TestAPITeam(t *testing.T) {
22 22
 
23 23
 	session := loginUser(t, user.Name)
24 24
 	req := NewRequestf(t, "GET", "/api/v1/teams/%d", teamUser.TeamID)
25
-	resp := session.MakeRequest(t, req)
26
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
25
+	resp := session.MakeRequest(t, req, http.StatusOK)
27 26
 
28 27
 	var apiTeam api.Team
29 28
 	DecodeJSON(t, resp, &apiTeam)

+ 7 - 19
integrations/change_default_branch_test.go

@@ -10,8 +10,6 @@ import (
10 10
 	"testing"
11 11
 
12 12
 	"code.gitea.io/gitea/models"
13
-
14
-	"github.com/stretchr/testify/assert"
15 13
 )
16 14
 
17 15
 func TestChangeDefaultBranch(t *testing.T) {
@@ -22,29 +20,19 @@ func TestChangeDefaultBranch(t *testing.T) {
22 20
 	session := loginUser(t, owner.Name)
23 21
 	branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
24 22
 
25
-	req := NewRequest(t, "GET", branchesURL)
26
-	resp := session.MakeRequest(t, req)
27
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
28
-	doc := NewHTMLParser(t, resp.Body)
29
-
30
-	req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
31
-		"_csrf":  doc.GetCSRF(),
23
+	csrf := GetCSRF(t, session, branchesURL)
24
+	req := NewRequestWithValues(t, "POST", branchesURL, map[string]string{
25
+		"_csrf":  csrf,
32 26
 		"action": "default_branch",
33 27
 		"branch": "DefaultBranch",
34 28
 	})
35
-	resp = session.MakeRequest(t, req)
36
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
37
-
38
-	req = NewRequest(t, "GET", branchesURL)
39
-	resp = session.MakeRequest(t, req)
40
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
41
-	doc = NewHTMLParser(t, resp.Body)
29
+	session.MakeRequest(t, req, http.StatusFound)
42 30
 
31
+	csrf = GetCSRF(t, session, branchesURL)
43 32
 	req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
44
-		"_csrf":  doc.GetInputValueByName("_csrf"),
33
+		"_csrf":  csrf,
45 34
 		"action": "default_branch",
46 35
 		"branch": "does_not_exist",
47 36
 	})
48
-	resp = session.MakeRequest(t, req)
49
-	assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
37
+	session.MakeRequest(t, req, http.StatusNotFound)
50 38
 }

+ 4 - 11
integrations/delete_user_test.go

@@ -9,8 +9,6 @@ import (
9 9
 	"testing"
10 10
 
11 11
 	"code.gitea.io/gitea/models"
12
-
13
-	"github.com/stretchr/testify/assert"
14 12
 )
15 13
 
16 14
 func TestDeleteUser(t *testing.T) {
@@ -18,16 +16,11 @@ func TestDeleteUser(t *testing.T) {
18 16
 
19 17
 	session := loginUser(t, "user1")
20 18
 
21
-	req := NewRequest(t, "GET", "/admin/users/8")
22
-	resp := session.MakeRequest(t, req)
23
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
24
-
25
-	doc := NewHTMLParser(t, resp.Body)
26
-	req = NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
27
-		"_csrf": doc.GetCSRF(),
19
+	csrf := GetCSRF(t, session, "/admin/users/8")
20
+	req := NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
21
+		"_csrf": csrf,
28 22
 	})
29
-	resp = session.MakeRequest(t, req)
30
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
23
+	session.MakeRequest(t, req, http.StatusOK)
31 24
 
32 25
 	models.AssertNotExistsBean(t, &models.User{ID: 8})
33 26
 	models.CheckConsistencyFor(t, &models.User{})

+ 15 - 32
integrations/editor_test.go

@@ -19,8 +19,7 @@ func TestCreateFile(t *testing.T) {
19 19
 
20 20
 	// Request editor page
21 21
 	req := NewRequest(t, "GET", "/user2/repo1/_new/master/")
22
-	resp := session.MakeRequest(t, req)
23
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
22
+	resp := session.MakeRequest(t, req, http.StatusOK)
24 23
 
25 24
 	doc := NewHTMLParser(t, resp.Body)
26 25
 	lastCommit := doc.GetInputValueByName("last_commit")
@@ -34,8 +33,7 @@ func TestCreateFile(t *testing.T) {
34 33
 		"content":       "Content",
35 34
 		"commit_choice": "direct",
36 35
 	})
37
-	resp = session.MakeRequest(t, req)
38
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
36
+	resp = session.MakeRequest(t, req, http.StatusFound)
39 37
 }
40 38
 
41 39
 func TestCreateFileOnProtectedBranch(t *testing.T) {
@@ -43,21 +41,14 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
43 41
 
44 42
 	session := loginUser(t, "user2")
45 43
 
46
-	// Open repository branch settings
47
-	req := NewRequest(t, "GET", "/user2/repo1/settings/branches")
48
-	resp := session.MakeRequest(t, req)
49
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
50
-
51
-	doc := NewHTMLParser(t, resp.Body)
52
-
44
+	csrf := GetCSRF(t, session, "/user2/repo1/settings/branches")
53 45
 	// Change master branch to protected
54
-	req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{
55
-		"_csrf":      doc.GetCSRF(),
46
+	req := NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{
47
+		"_csrf":      csrf,
56 48
 		"branchName": "master",
57 49
 		"canPush":    "true",
58 50
 	})
59
-	resp = session.MakeRequest(t, req)
60
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
51
+	resp := session.MakeRequest(t, req, http.StatusOK)
61 52
 	// Check if master branch has been locked successfully
62 53
 	flashCookie := session.GetCookie("macaron_flash")
63 54
 	assert.NotNil(t, flashCookie)
@@ -65,10 +56,9 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
65 56
 
66 57
 	// Request editor page
67 58
 	req = NewRequest(t, "GET", "/user2/repo1/_new/master/")
68
-	resp = session.MakeRequest(t, req)
69
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
59
+	resp = session.MakeRequest(t, req, http.StatusOK)
70 60
 
71
-	doc = NewHTMLParser(t, resp.Body)
61
+	doc := NewHTMLParser(t, resp.Body)
72 62
 	lastCommit := doc.GetInputValueByName("last_commit")
73 63
 	assert.NotEmpty(t, lastCommit)
74 64
 
@@ -81,8 +71,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
81 71
 		"commit_choice": "direct",
82 72
 	})
83 73
 
84
-	resp = session.MakeRequest(t, req)
85
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
74
+	resp = session.MakeRequest(t, req, http.StatusOK)
86 75
 	// Check body for error message
87 76
 	assert.Contains(t, string(resp.Body), "Can not commit to protected branch 'master'.")
88 77
 }
@@ -93,8 +82,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
93 82
 
94 83
 	// Get to the 'edit this file' page
95 84
 	req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
96
-	resp := session.MakeRequest(t, req)
97
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
85
+	resp := session.MakeRequest(t, req, http.StatusOK)
98 86
 
99 87
 	htmlDoc := NewHTMLParser(t, resp.Body)
100 88
 	lastCommit := htmlDoc.GetInputValueByName("last_commit")
@@ -110,13 +98,11 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
110 98
 			"commit_choice": "direct",
111 99
 		},
112 100
 	)
113
-	resp = session.MakeRequest(t, req)
114
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
101
+	resp = session.MakeRequest(t, req, http.StatusFound)
115 102
 
116 103
 	// Verify the change
117 104
 	req = NewRequest(t, "GET", path.Join(user, repo, "raw", branch, filePath))
118
-	resp = session.MakeRequest(t, req)
119
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
105
+	resp = session.MakeRequest(t, req, http.StatusOK)
120 106
 	assert.EqualValues(t, newContent, string(resp.Body))
121 107
 
122 108
 	return resp
@@ -128,8 +114,7 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
128 114
 
129 115
 	// Get to the 'edit this file' page
130 116
 	req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
131
-	resp := session.MakeRequest(t, req)
132
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
117
+	resp := session.MakeRequest(t, req, http.StatusOK)
133 118
 
134 119
 	htmlDoc := NewHTMLParser(t, resp.Body)
135 120
 	lastCommit := htmlDoc.GetInputValueByName("last_commit")
@@ -146,13 +131,11 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
146 131
 			"new_branch_name": targetBranch,
147 132
 		},
148 133
 	)
149
-	resp = session.MakeRequest(t, req)
150
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
134
+	resp = session.MakeRequest(t, req, http.StatusFound)
151 135
 
152 136
 	// Verify the change
153 137
 	req = NewRequest(t, "GET", path.Join(user, repo, "raw", targetBranch, filePath))
154
-	resp = session.MakeRequest(t, req)
155
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
138
+	resp = session.MakeRequest(t, req, http.StatusOK)
156 139
 	assert.EqualValues(t, newContent, string(resp.Body))
157 140
 
158 141
 	return resp

+ 23 - 7
integrations/integration_test.go

@@ -140,13 +140,13 @@ func (s *TestSession) GetCookie(name string) *http.Cookie {
140 140
 	return nil
141 141
 }
142 142
 
143
-func (s *TestSession) MakeRequest(t testing.TB, req *http.Request) *TestResponse {
143
+func (s *TestSession) MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *TestResponse {
144 144
 	baseURL, err := url.Parse(setting.AppURL)
145 145
 	assert.NoError(t, err)
146 146
 	for _, c := range s.jar.Cookies(baseURL) {
147 147
 		req.AddCookie(c)
148 148
 	}
149
-	resp := MakeRequest(req)
149
+	resp := MakeRequest(t, req, expectedStatus)
150 150
 
151 151
 	ch := http.Header{}
152 152
 	ch.Add("Cookie", strings.Join(resp.Headers["Set-Cookie"], ";"))
@@ -164,8 +164,7 @@ func loginUser(t testing.TB, userName string) *TestSession {
164 164
 
165 165
 func loginUserWithPassword(t testing.TB, userName, password string) *TestSession {
166 166
 	req := NewRequest(t, "GET", "/user/login")
167
-	resp := MakeRequest(req)
168
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
167
+	resp := MakeRequest(t, req, http.StatusOK)
169 168
 
170 169
 	doc := NewHTMLParser(t, resp.Body)
171 170
 	req = NewRequestWithValues(t, "POST", "/user/login", map[string]string{
@@ -173,8 +172,7 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession
173 172
 		"user_name": userName,
174 173
 		"password":  password,
175 174
 	})
176
-	resp = MakeRequest(req)
177
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
175
+	resp = MakeRequest(t, req, http.StatusFound)
178 176
 
179 177
 	ch := http.Header{}
180 178
 	ch.Add("Cookie", strings.Join(resp.Headers["Set-Cookie"], ";"))
@@ -246,13 +244,18 @@ func NewRequestWithBody(t testing.TB, method, urlStr string, body io.Reader) *ht
246 244
 	return request
247 245
 }
248 246
 
249
-func MakeRequest(req *http.Request) *TestResponse {
247
+const NoExpectedStatus = -1
248
+
249
+func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *TestResponse {
250 250
 	buffer := bytes.NewBuffer(nil)
251 251
 	respWriter := &TestResponseWriter{
252 252
 		Writer:  buffer,
253 253
 		Headers: make(map[string][]string),
254 254
 	}
255 255
 	mac.ServeHTTP(respWriter, req)
256
+	if expectedStatus != NoExpectedStatus {
257
+		assert.EqualValues(t, expectedStatus, respWriter.HeaderCode)
258
+	}
256 259
 	return &TestResponse{
257 260
 		HeaderCode: respWriter.HeaderCode,
258 261
 		Body:       buffer.Bytes(),
@@ -264,3 +267,16 @@ func DecodeJSON(t testing.TB, resp *TestResponse, v interface{}) {
264 267
 	decoder := json.NewDecoder(bytes.NewBuffer(resp.Body))
265 268
 	assert.NoError(t, decoder.Decode(v))
266 269
 }
270
+
271
+func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
272
+	req := NewRequest(t, "GET", urlStr)
273
+	resp := session.MakeRequest(t, req, http.StatusOK)
274
+	doc := NewHTMLParser(t, resp.Body)
275
+	return doc.GetCSRF()
276
+}
277
+
278
+func RedirectURL(t testing.TB, resp *TestResponse) string {
279
+	urlSlice := resp.Headers["Location"]
280
+	assert.NotEmpty(t, urlSlice, "No redirect URL founds")
281
+	return urlSlice[0]
282
+}

+ 2 - 2
integrations/internal_test.go

@@ -23,9 +23,9 @@ func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr,
23 23
 	t.Log(reqURL)
24 24
 	req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken))
25 25
 
26
-	resp := MakeRequest(req)
26
+	resp := MakeRequest(t, req, NoExpectedStatus)
27 27
 	if isErr {
28
-		assert.EqualValues(t, 500, resp.HeaderCode)
28
+		assert.EqualValues(t, http.StatusInternalServerError, resp.HeaderCode)
29 29
 	} else {
30 30
 		assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
31 31
 		var branch models.ProtectedBranch

+ 8 - 16
integrations/issue_test.go

@@ -35,8 +35,7 @@ func TestNoLoginViewIssues(t *testing.T) {
35 35
 	prepareTestEnv(t)
36 36
 
37 37
 	req := NewRequest(t, "GET", "/user2/repo1/issues")
38
-	resp := MakeRequest(req)
39
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
38
+	MakeRequest(t, req, http.StatusOK)
40 39
 }
41 40
 
42 41
 func TestNoLoginViewIssuesSortByType(t *testing.T) {
@@ -48,8 +47,7 @@ func TestNoLoginViewIssuesSortByType(t *testing.T) {
48 47
 
49 48
 	session := loginUser(t, user.Name)
50 49
 	req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by")
51
-	resp := session.MakeRequest(t, req)
52
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
50
+	resp := session.MakeRequest(t, req, http.StatusOK)
53 51
 
54 52
 	htmlDoc := NewHTMLParser(t, resp.Body)
55 53
 	issuesSelection := getIssuesSelection(htmlDoc)
@@ -73,15 +71,13 @@ func TestNoLoginViewIssue(t *testing.T) {
73 71
 	prepareTestEnv(t)
74 72
 
75 73
 	req := NewRequest(t, "GET", "/user2/repo1/issues/1")
76
-	resp := MakeRequest(req)
77
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
74
+	MakeRequest(t, req, http.StatusOK)
78 75
 }
79 76
 
80 77
 func testNewIssue(t *testing.T, session *TestSession, user, repo, title string) {
81 78
 
82 79
 	req := NewRequest(t, "GET", path.Join(user, repo, "issues", "new"))
83
-	resp := session.MakeRequest(t, req)
84
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
80
+	resp := session.MakeRequest(t, req, http.StatusOK)
85 81
 
86 82
 	htmlDoc := NewHTMLParser(t, resp.Body)
87 83
 	link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
@@ -90,14 +86,10 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title string)
90 86
 		"_csrf": htmlDoc.GetCSRF(),
91 87
 		"title": title,
92 88
 	})
93
-	resp = session.MakeRequest(t, req)
94
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
95
-	redirectedURL := resp.Headers["Location"]
96
-	assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
97
-
98
-	req = NewRequest(t, "GET", redirectedURL[0])
99
-	resp = session.MakeRequest(t, req)
100
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
89
+	resp = session.MakeRequest(t, req, http.StatusFound)
90
+
91
+	req = NewRequest(t, "GET", RedirectURL(t, resp))
92
+	resp = session.MakeRequest(t, req, http.StatusOK)
101 93
 }
102 94
 
103 95
 func TestNewIssue(t *testing.T) {

+ 2 - 3
integrations/pull_compare_test.go

@@ -16,13 +16,12 @@ func TestPullCompare(t *testing.T) {
16 16
 
17 17
 	session := loginUser(t, "user2")
18 18
 	req := NewRequest(t, "GET", "/user2/repo1/pulls")
19
-	resp := session.MakeRequest(t, req)
20
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
19
+	resp := session.MakeRequest(t, req, http.StatusOK)
21 20
 	htmlDoc := NewHTMLParser(t, resp.Body)
22 21
 	link, exists := htmlDoc.doc.Find(".navbar").Find(".ui.green.button").Attr("href")
23 22
 	assert.True(t, exists, "The template has changed")
24 23
 
25 24
 	req = NewRequest(t, "GET", link)
26
-	resp = session.MakeRequest(t, req)
25
+	resp = session.MakeRequest(t, req, http.StatusOK)
27 26
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
28 27
 }

+ 3 - 6
integrations/pull_create_test.go

@@ -15,8 +15,7 @@ import (
15 15
 
16 16
 func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *TestResponse {
17 17
 	req := NewRequest(t, "GET", path.Join(user, repo))
18
-	resp := session.MakeRequest(t, req)
19
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
18
+	resp := session.MakeRequest(t, req, http.StatusOK)
20 19
 
21 20
 	// Click the little green button to create a pull
22 21
 	htmlDoc := NewHTMLParser(t, resp.Body)
@@ -27,8 +26,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
27 26
 	}
28 27
 
29 28
 	req = NewRequest(t, "GET", link)
30
-	resp = session.MakeRequest(t, req)
31
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
29
+	resp = session.MakeRequest(t, req, http.StatusOK)
32 30
 
33 31
 	// Submit the form for creating the pull
34 32
 	htmlDoc = NewHTMLParser(t, resp.Body)
@@ -38,8 +36,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
38 36
 		"_csrf": htmlDoc.GetCSRF(),
39 37
 		"title": "This is a pull title",
40 38
 	})
41
-	resp = session.MakeRequest(t, req)
42
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
39
+	resp = session.MakeRequest(t, req, http.StatusFound)
43 40
 
44 41
 	//TODO check the redirected URL
45 42
 

+ 9 - 18
integrations/pull_merge_test.go

@@ -15,36 +15,32 @@ import (
15 15
 
16 16
 func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
17 17
 	req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
18
-	resp := session.MakeRequest(t, req)
19
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
18
+	resp := session.MakeRequest(t, req, http.StatusOK)
20 19
 
21
-	// Click the little green button to craete a pull
20
+	// Click the little green button to create a pull
22 21
 	htmlDoc := NewHTMLParser(t, resp.Body)
23 22
 	link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
24 23
 	assert.True(t, exists, "The template has changed")
25 24
 	req = NewRequestWithValues(t, "POST", link, map[string]string{
26 25
 		"_csrf": htmlDoc.GetCSRF(),
27 26
 	})
28
-	resp = session.MakeRequest(t, req)
29
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
27
+	resp = session.MakeRequest(t, req, http.StatusFound)
30 28
 
31 29
 	return resp
32 30
 }
33 31
 
34 32
 func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
35 33
 	req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
36
-	resp := session.MakeRequest(t, req)
37
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
34
+	resp := session.MakeRequest(t, req, http.StatusOK)
38 35
 
39
-	// Click the little green button to craete a pull
36
+	// Click the little green button to create a pull
40 37
 	htmlDoc := NewHTMLParser(t, resp.Body)
41 38
 	link, exists := htmlDoc.doc.Find(".comments .merge .delete-button").Attr("data-url")
42 39
 	assert.True(t, exists, "The template has changed")
43 40
 	req = NewRequestWithValues(t, "POST", link, map[string]string{
44 41
 		"_csrf": htmlDoc.GetCSRF(),
45 42
 	})
46
-	resp = session.MakeRequest(t, req)
47
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
43
+	resp = session.MakeRequest(t, req, http.StatusOK)
48 44
 
49 45
 	return resp
50 46
 }
@@ -56,10 +52,8 @@ func TestPullMerge(t *testing.T) {
56 52
 	testEditFile(t, session, "user1", "repo1", "master", "README.md")
57 53
 
58 54
 	resp := testPullCreate(t, session, "user1", "repo1", "master")
59
-	redirectedURL := resp.Headers["Location"]
60
-	assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
61 55
 
62
-	elem := strings.Split(redirectedURL[0], "/")
56
+	elem := strings.Split(RedirectURL(t, resp), "/")
63 57
 	assert.EqualValues(t, "pulls", elem[3])
64 58
 	testPullMerge(t, session, elem[1], elem[2], elem[4])
65 59
 }
@@ -71,10 +65,8 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
71 65
 	testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md")
72 66
 
73 67
 	resp := testPullCreate(t, session, "user1", "repo1", "feature/test")
74
-	redirectedURL := resp.Headers["Location"]
75
-	assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
76 68
 
77
-	elem := strings.Split(redirectedURL[0], "/")
69
+	elem := strings.Split(RedirectURL(t, resp), "/")
78 70
 	assert.EqualValues(t, "pulls", elem[3])
79 71
 	testPullMerge(t, session, elem[1], elem[2], elem[4])
80 72
 
@@ -92,8 +84,7 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
92 84
 
93 85
 	// Check branch deletion result
94 86
 	req := NewRequest(t, "GET", respJSON.Redirect)
95
-	resp = session.MakeRequest(t, req)
96
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
87
+	resp = session.MakeRequest(t, req, http.StatusOK)
97 88
 
98 89
 	htmlDoc := NewHTMLParser(t, resp.Body)
99 90
 	resultMsg := htmlDoc.doc.Find(".ui.message>p").Text()

+ 6 - 12
integrations/release_test.go

@@ -15,8 +15,7 @@ import (
15 15
 
16 16
 func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {
17 17
 	req := NewRequest(t, "GET", repoURL+"/releases/new")
18
-	resp := session.MakeRequest(t, req)
19
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
18
+	resp := session.MakeRequest(t, req, http.StatusOK)
20 19
 	htmlDoc := NewHTMLParser(t, resp.Body)
21 20
 
22 21
 	link, exists := htmlDoc.doc.Find("form").Attr("action")
@@ -37,17 +36,14 @@ func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title st
37 36
 	}
38 37
 	req = NewRequestWithValues(t, "POST", link, postData)
39 38
 
40
-	resp = session.MakeRequest(t, req)
41
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
39
+	resp = session.MakeRequest(t, req, http.StatusFound)
42 40
 
43
-	redirectedURL := resp.Headers["Location"]
44
-	assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
41
+	RedirectURL(t, resp) // check that redirect URL exists
45 42
 }
46 43
 
47 44
 func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, version, label string, count int) {
48 45
 	req := NewRequest(t, "GET", repoURL+"/releases")
49
-	resp := session.MakeRequest(t, req)
50
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
46
+	resp := session.MakeRequest(t, req, http.StatusOK)
51 47
 
52 48
 	htmlDoc := NewHTMLParser(t, resp.Body)
53 49
 	labelText := htmlDoc.doc.Find("#release-list > li .meta .label").First().Text()
@@ -64,16 +60,14 @@ func TestViewReleases(t *testing.T) {
64 60
 
65 61
 	session := loginUser(t, "user2")
66 62
 	req := NewRequest(t, "GET", "/user2/repo1/releases")
67
-	resp := session.MakeRequest(t, req)
68
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
63
+	session.MakeRequest(t, req, http.StatusOK)
69 64
 }
70 65
 
71 66
 func TestViewReleasesNoLogin(t *testing.T) {
72 67
 	prepareTestEnv(t)
73 68
 
74 69
 	req := NewRequest(t, "GET", "/user2/repo1/releases")
75
-	resp := MakeRequest(req)
76
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
70
+	MakeRequest(t, req, http.StatusOK)
77 71
 }
78 72
 
79 73
 func TestCreateRelease(t *testing.T) {

+ 4 - 8
integrations/repo_commits_test.go

@@ -21,8 +21,7 @@ func TestRepoCommits(t *testing.T) {
21 21
 
22 22
 	// Request repository commits page
23 23
 	req := NewRequest(t, "GET", "/user2/repo1/commits/master")
24
-	resp := session.MakeRequest(t, req)
25
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
24
+	resp := session.MakeRequest(t, req, http.StatusOK)
26 25
 
27 26
 	doc := NewHTMLParser(t, resp.Body)
28 27
 	commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
@@ -37,8 +36,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
37 36
 
38 37
 	// Request repository commits page
39 38
 	req := NewRequest(t, "GET", "/user2/repo1/commits/master")
40
-	resp := session.MakeRequest(t, req)
41
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
39
+	resp := session.MakeRequest(t, req, http.StatusOK)
42 40
 
43 41
 	doc := NewHTMLParser(t, resp.Body)
44 42
 	// Get first commit URL
@@ -56,12 +54,10 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
56 54
 		},
57 55
 	)
58 56
 
59
-	resp = session.MakeRequest(t, req)
60
-	assert.EqualValues(t, http.StatusCreated, resp.HeaderCode)
57
+	resp = session.MakeRequest(t, req, http.StatusCreated)
61 58
 
62 59
 	req = NewRequest(t, "GET", "/user2/repo1/commits/master")
63
-	resp = session.MakeRequest(t, req)
64
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
60
+	resp = session.MakeRequest(t, req, http.StatusOK)
65 61
 
66 62
 	doc = NewHTMLParser(t, resp.Body)
67 63
 	// Check if commit status is displayed in message column

+ 5 - 10
integrations/repo_fork_test.go

@@ -14,21 +14,18 @@ import (
14 14
 func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
15 15
 	// Step0: check the existence of the to-fork repo
16 16
 	req := NewRequest(t, "GET", "/user1/repo1")
17
-	resp := session.MakeRequest(t, req)
18
-	assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
17
+	resp := session.MakeRequest(t, req, http.StatusNotFound)
19 18
 
20 19
 	// Step1: go to the main page of repo
21 20
 	req = NewRequest(t, "GET", "/user2/repo1")
22
-	resp = session.MakeRequest(t, req)
23
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
21
+	resp = session.MakeRequest(t, req, http.StatusOK)
24 22
 
25 23
 	// Step2: click the fork button
26 24
 	htmlDoc := NewHTMLParser(t, resp.Body)
27 25
 	link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
28 26
 	assert.True(t, exists, "The template has changed")
29 27
 	req = NewRequest(t, "GET", link)
30
-	resp = session.MakeRequest(t, req)
31
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
28
+	resp = session.MakeRequest(t, req, http.StatusOK)
32 29
 
33 30
 	// Step3: fill the form of the forking
34 31
 	htmlDoc = NewHTMLParser(t, resp.Body)
@@ -39,13 +36,11 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
39 36
 		"uid":       "1",
40 37
 		"repo_name": "repo1",
41 38
 	})
42
-	resp = session.MakeRequest(t, req)
43
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
39
+	resp = session.MakeRequest(t, req, http.StatusFound)
44 40
 
45 41
 	// Step4: check the existence of the forked repo
46 42
 	req = NewRequest(t, "GET", "/user1/repo1")
47
-	resp = session.MakeRequest(t, req)
48
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
43
+	resp = session.MakeRequest(t, req, http.StatusOK)
49 44
 
50 45
 	return resp
51 46
 }

+ 2 - 4
integrations/repo_migrate_test.go

@@ -13,8 +13,7 @@ import (
13 13
 
14 14
 func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName string) *TestResponse {
15 15
 	req := NewRequest(t, "GET", "/repo/migrate")
16
-	resp := session.MakeRequest(t, req)
17
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
16
+	resp := session.MakeRequest(t, req, http.StatusOK)
18 17
 	htmlDoc := NewHTMLParser(t, resp.Body)
19 18
 
20 19
 	link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
@@ -30,8 +29,7 @@ func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName str
30 29
 		"repo_name":  repoName,
31 30
 	},
32 31
 	)
33
-	resp = session.MakeRequest(t, req)
34
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
32
+	resp = session.MakeRequest(t, req, http.StatusFound)
35 33
 
36 34
 	return resp
37 35
 }

+ 5 - 12
integrations/repo_test.go

@@ -7,24 +7,19 @@ package integrations
7 7
 import (
8 8
 	"net/http"
9 9
 	"testing"
10
-
11
-	"github.com/stretchr/testify/assert"
12 10
 )
13 11
 
14 12
 func TestViewRepo(t *testing.T) {
15 13
 	prepareTestEnv(t)
16 14
 
17 15
 	req := NewRequest(t, "GET", "/user2/repo1")
18
-	resp := MakeRequest(req)
19
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
16
+	MakeRequest(t, req, http.StatusOK)
20 17
 
21 18
 	req = NewRequest(t, "GET", "/user3/repo3")
22
-	resp = MakeRequest(req)
23
-	assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
19
+	MakeRequest(t, req, http.StatusNotFound)
24 20
 
25 21
 	session := loginUser(t, "user1")
26
-	resp = session.MakeRequest(t, req)
27
-	assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
22
+	session.MakeRequest(t, req, http.StatusNotFound)
28 23
 }
29 24
 
30 25
 func TestViewRepo2(t *testing.T) {
@@ -32,8 +27,7 @@ func TestViewRepo2(t *testing.T) {
32 27
 
33 28
 	req := NewRequest(t, "GET", "/user3/repo3")
34 29
 	session := loginUser(t, "user2")
35
-	resp := session.MakeRequest(t, req)
36
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
30
+	session.MakeRequest(t, req, http.StatusOK)
37 31
 }
38 32
 
39 33
 func TestViewRepo3(t *testing.T) {
@@ -41,6 +35,5 @@ func TestViewRepo3(t *testing.T) {
41 35
 
42 36
 	req := NewRequest(t, "GET", "/user3/repo3")
43 37
 	session := loginUser(t, "user3")
44
-	resp := session.MakeRequest(t, req)
45
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
38
+	session.MakeRequest(t, req, http.StatusOK)
46 39
 }

+ 2 - 6
integrations/signup_test.go

@@ -9,8 +9,6 @@ import (
9 9
 	"testing"
10 10
 
11 11
 	"code.gitea.io/gitea/modules/setting"
12
-
13
-	"github.com/stretchr/testify/assert"
14 12
 )
15 13
 
16 14
 func TestSignup(t *testing.T) {
@@ -24,11 +22,9 @@ func TestSignup(t *testing.T) {
24 22
 		"password":  "examplePassword",
25 23
 		"retype":    "examplePassword",
26 24
 	})
27
-	resp := MakeRequest(req)
28
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
25
+	MakeRequest(t, req, http.StatusFound)
29 26
 
30 27
 	// should be able to view new user's page
31 28
 	req = NewRequest(t, "GET", "/exampleUser")
32
-	resp = MakeRequest(req)
33
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
29
+	MakeRequest(t, req, http.StatusOK)
34 30
 }

+ 14 - 34
integrations/user_test.go

@@ -18,27 +18,19 @@ func TestViewUser(t *testing.T) {
18 18
 	prepareTestEnv(t)
19 19
 
20 20
 	req := NewRequest(t, "GET", "/user2")
21
-	resp := MakeRequest(req)
22
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
21
+	MakeRequest(t, req, http.StatusOK)
23 22
 }
24 23
 
25 24
 func TestRenameUsername(t *testing.T) {
26 25
 	prepareTestEnv(t)
27 26
 
28 27
 	session := loginUser(t, "user2")
29
-
30
-	req := NewRequest(t, "GET", "/user/settings")
31
-	resp := session.MakeRequest(t, req)
32
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
33
-
34
-	htmlDoc := NewHTMLParser(t, resp.Body)
35
-	req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
36
-		"_csrf": htmlDoc.GetCSRF(),
28
+	req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
29
+		"_csrf": GetCSRF(t, session, "/user/settings"),
37 30
 		"name":  "newUsername",
38 31
 		"email": "user2@example.com",
39 32
 	})
40
-	resp = session.MakeRequest(t, req)
41
-	assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
33
+	session.MakeRequest(t, req, http.StatusFound)
42 34
 
43 35
 	models.AssertExistsAndLoadBean(t, &models.User{Name: "newUsername"})
44 36
 	models.AssertNotExistsBean(t, &models.User{Name: "user2"})
@@ -58,19 +50,14 @@ func TestRenameInvalidUsername(t *testing.T) {
58 50
 	session := loginUser(t, "user2")
59 51
 	for _, invalidUsername := range invalidUsernames {
60 52
 		t.Logf("Testing username %s", invalidUsername)
61
-		req := NewRequest(t, "GET", "/user/settings")
62
-		resp := session.MakeRequest(t, req)
63
-		assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
64 53
 
65
-		htmlDoc := NewHTMLParser(t, resp.Body)
66
-		req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
67
-			"_csrf": htmlDoc.GetCSRF(),
54
+		req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
55
+			"_csrf": GetCSRF(t, session, "/user/settings"),
68 56
 			"name":  invalidUsername,
69 57
 			"email": "user2@example.com",
70 58
 		})
71
-		resp = session.MakeRequest(t, req)
72
-		assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
73
-		htmlDoc = NewHTMLParser(t, resp.Body)
59
+		resp := session.MakeRequest(t, req, http.StatusOK)
60
+		htmlDoc := NewHTMLParser(t, resp.Body)
74 61
 		assert.Contains(t,
75 62
 			htmlDoc.doc.Find(".ui.negative.message").Text(),
76 63
 			i18n.Tr("en", "form.alpha_dash_dot_error"),
@@ -92,23 +79,16 @@ func TestRenameReservedUsername(t *testing.T) {
92 79
 	session := loginUser(t, "user2")
93 80
 	for _, reservedUsername := range reservedUsernames {
94 81
 		t.Logf("Testing username %s", reservedUsername)
95
-		req := NewRequest(t, "GET", "/user/settings")
96
-		resp := session.MakeRequest(t, req)
97
-		assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
98
-
99
-		htmlDoc := NewHTMLParser(t, resp.Body)
100
-		req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
101
-			"_csrf": htmlDoc.GetCSRF(),
82
+		req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
83
+			"_csrf": GetCSRF(t, session, "/user/settings"),
102 84
 			"name":  reservedUsername,
103 85
 			"email": "user2@example.com",
104 86
 		})
105
-		resp = session.MakeRequest(t, req)
106
-		assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
87
+		resp := session.MakeRequest(t, req, http.StatusFound)
107 88
 
108
-		req = NewRequest(t, "GET", "/user/settings")
109
-		resp = session.MakeRequest(t, req)
110
-		assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
111
-		htmlDoc = NewHTMLParser(t, resp.Body)
89
+		req = NewRequest(t, "GET", RedirectURL(t, resp))
90
+		resp = session.MakeRequest(t, req, http.StatusOK)
91
+		htmlDoc := NewHTMLParser(t, resp.Body)
112 92
 		assert.Contains(t,
113 93
 			htmlDoc.doc.Find(".ui.negative.message").Text(),
114 94
 			i18n.Tr("en", "user.newName_reserved"),

+ 1 - 2
integrations/version_test.go

@@ -19,8 +19,7 @@ func TestVersion(t *testing.T) {
19 19
 
20 20
 	setting.AppVer = "1.1.0+dev"
21 21
 	req := NewRequest(t, "GET", "/api/v1/version")
22
-	resp := MakeRequest(req)
23
-	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
22
+	resp := MakeRequest(t, req, http.StatusOK)
24 23
 
25 24
 	var version gitea.ServerVersion
26 25
 	DecodeJSON(t, resp, &version)