2017-06-07 02:27:49 +00:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-06-15 11:20:39 +00:00
|
|
|
func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
2017-06-07 02:27:49 +00:00
|
|
|
// Step0: check the existence of the to-fork repo
|
2017-06-10 00:41:36 +00:00
|
|
|
req := NewRequest(t, "GET", "/user1/repo1")
|
2017-06-07 02:27:49 +00:00
|
|
|
resp := session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step1: go to the main page of repo
|
2017-06-10 00:41:36 +00:00
|
|
|
req = NewRequest(t, "GET", "/user2/repo1")
|
2017-06-07 02:27:49 +00:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step2: click the fork button
|
2017-06-17 16:29:59 +00:00
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
2017-06-07 02:27:49 +00:00
|
|
|
link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
|
|
|
|
assert.True(t, exists, "The template has changed")
|
2017-06-10 00:41:36 +00:00
|
|
|
req = NewRequest(t, "GET", link)
|
2017-06-07 02:27:49 +00:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step3: fill the form of the forking
|
2017-06-17 16:29:59 +00:00
|
|
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
2017-06-07 02:27:49 +00:00
|
|
|
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action")
|
|
|
|
assert.True(t, exists, "The template has changed")
|
2017-06-17 04:49:45 +00:00
|
|
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"uid": "1",
|
|
|
|
"repo_name": "repo1",
|
|
|
|
})
|
2017-06-07 02:27:49 +00:00
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step4: check the existence of the forked repo
|
2017-06-10 00:41:36 +00:00
|
|
|
req = NewRequest(t, "GET", "/user1/repo1")
|
2017-06-07 02:27:49 +00:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
2017-06-15 11:20:39 +00:00
|
|
|
|
|
|
|
return resp
|
2017-06-07 02:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepoFork(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
2017-06-17 04:49:45 +00:00
|
|
|
session := loginUser(t, "user1")
|
2017-06-07 02:27:49 +00:00
|
|
|
testRepoFork(t, session)
|
|
|
|
}
|