Skip to content

Commit f4eac2f

Browse files
committed
Add integration test for pull-request merge
1 parent 033aaf4 commit f4eac2f

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

integrations/editor_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
101101
assert.Contains(t, string(resp.Body), "Can not commit to protected branch 'master'.")
102102
}
103103

104-
func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath string) {
104+
func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath string) *TestResponse {
105105

106106
newContent := "Hello, World (Edited)\n"
107107

@@ -134,6 +134,8 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
134134
resp = session.MakeRequest(t, req)
135135
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
136136
assert.EqualValues(t, newContent, string(resp.Body))
137+
138+
return resp
137139
}
138140

139141
func TestEditFile(t *testing.T) {

integrations/pull_create_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/stretchr/testify/assert"
1515
)
1616

17-
func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) {
17+
func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *TestResponse {
1818
req := NewRequest(t, "GET", path.Join(user, repo))
1919
resp := session.MakeRequest(t, req)
2020
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
@@ -45,6 +45,8 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
4545
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
4646

4747
//TODO check the redirected URL
48+
49+
return resp
4850
}
4951

5052
func TestPullCreate(t *testing.T) {

integrations/pull_merge_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"bytes"
9+
"net/http"
10+
"net/url"
11+
"path"
12+
"strings"
13+
"testing"
14+
15+
"github.com/stretchr/testify/assert"
16+
)
17+
18+
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
19+
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
20+
resp := session.MakeRequest(t, req)
21+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
22+
23+
// Click the little green button to craete a pull
24+
htmlDoc, err := NewHtmlParser(resp.Body)
25+
assert.NoError(t, err)
26+
link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
27+
assert.True(t, exists, "The template has changed")
28+
req = NewRequestBody(t, "POST", link,
29+
bytes.NewBufferString(url.Values{
30+
"_csrf": []string{htmlDoc.GetInputValueByName("_csrf")},
31+
}.Encode()),
32+
)
33+
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
34+
resp = session.MakeRequest(t, req)
35+
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
36+
37+
return resp
38+
}
39+
40+
func TestPullMerge(t *testing.T) {
41+
prepareTestEnv(t)
42+
session := loginUser(t, "user1", "password")
43+
testRepoFork(t, session)
44+
testEditFile(t, session, "user1", "repo1", "master", "README.md")
45+
46+
resp := testPullCreate(t, session, "user1", "repo1", "master")
47+
redirectedURL := resp.Headers["Location"]
48+
assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
49+
50+
elem := strings.Split(redirectedURL[0], "/")
51+
assert.EqualValues(t, "pulls", elem[3])
52+
testPullMerge(t, session, elem[1], elem[2], elem[4])
53+
}

integrations/repo_fork_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
)
1515

16-
func testRepoFork(t *testing.T, session *TestSession) {
16+
func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
1717
// Step0: check the existence of the to-fork repo
1818
req := NewRequest(t, "GET", "/user1/repo1")
1919
resp := session.MakeRequest(t, req)
@@ -53,6 +53,8 @@ func testRepoFork(t *testing.T, session *TestSession) {
5353
req = NewRequest(t, "GET", "/user1/repo1")
5454
resp = session.MakeRequest(t, req)
5555
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
56+
57+
return resp
5658
}
5759

5860
func TestRepoFork(t *testing.T) {

0 commit comments

Comments
 (0)