Skip to content

Commit 815715e

Browse files
authored
Merge pull request #1896 from typeless/add-integration-test-for-forking
Add integration test for repository forking
2 parents 4bc7240 + 30a8316 commit 815715e

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

integrations/repo_fork_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
"testing"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func testRepoFork(t *testing.T, session *TestSession) {
17+
// Step0: check the existence of the to-fork repo
18+
req, err := http.NewRequest("GET", "/user1/repo1", nil)
19+
assert.NoError(t, err)
20+
resp := session.MakeRequest(t, req)
21+
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
22+
23+
// Step1: go to the main page of repo
24+
req, err = http.NewRequest("GET", "/user2/repo1", nil)
25+
assert.NoError(t, err)
26+
resp = session.MakeRequest(t, req)
27+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
28+
29+
// Step2: click the fork button
30+
htmlDoc, err := NewHtmlParser(resp.Body)
31+
assert.NoError(t, err)
32+
link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
33+
assert.True(t, exists, "The template has changed")
34+
req, err = http.NewRequest("GET", link, nil)
35+
assert.NoError(t, err)
36+
resp = session.MakeRequest(t, req)
37+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
38+
39+
// Step3: fill the form of the forking
40+
htmlDoc, err = NewHtmlParser(resp.Body)
41+
assert.NoError(t, err)
42+
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action")
43+
assert.True(t, exists, "The template has changed")
44+
req, err = http.NewRequest("POST", link,
45+
bytes.NewBufferString(url.Values{
46+
"_csrf": []string{htmlDoc.GetInputValueByName("_csrf")},
47+
"uid": []string{"1"},
48+
"repo_name": []string{"repo1"},
49+
}.Encode()),
50+
)
51+
assert.NoError(t, err)
52+
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
53+
resp = session.MakeRequest(t, req)
54+
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
55+
56+
// Step4: check the existence of the forked repo
57+
req, err = http.NewRequest("GET", "/user1/repo1", nil)
58+
assert.NoError(t, err)
59+
resp = session.MakeRequest(t, req)
60+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
61+
}
62+
63+
func TestRepoFork(t *testing.T) {
64+
prepareTestEnv(t)
65+
session := loginUser(t, "user1", "password")
66+
testRepoFork(t, session)
67+
}

0 commit comments

Comments
 (0)