2017-06-06 22:27:49 -04: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 07:20:39 -04:00
|
|
|
func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
2017-06-06 22:27:49 -04:00
|
|
|
// Step0: check the existence of the to-fork repo
|
2017-06-09 20:41:36 -04:00
|
|
|
req := NewRequest(t, "GET", "/user1/repo1")
|
2017-06-06 22:27:49 -04:00
|
|
|
resp := session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step1: go to the main page of repo
|
2017-06-09 20:41:36 -04:00
|
|
|
req = NewRequest(t, "GET", "/user2/repo1")
|
2017-06-06 22:27:49 -04:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step2: click the fork button
|
2017-06-17 12:29:59 -04:00
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
2017-06-06 22:27:49 -04:00
|
|
|
link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
|
|
|
|
assert.True(t, exists, "The template has changed")
|
2017-06-09 20:41:36 -04:00
|
|
|
req = NewRequest(t, "GET", link)
|
2017-06-06 22:27:49 -04:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step3: fill the form of the forking
|
2017-06-17 12:29:59 -04:00
|
|
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
2017-06-06 22:27:49 -04: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 00:49:45 -04:00
|
|
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"uid": "1",
|
|
|
|
"repo_name": "repo1",
|
|
|
|
})
|
2017-06-06 22:27:49 -04: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-09 20:41:36 -04:00
|
|
|
req = NewRequest(t, "GET", "/user1/repo1")
|
2017-06-06 22:27:49 -04:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
2017-06-15 07:20:39 -04:00
|
|
|
|
|
|
|
return resp
|
2017-06-06 22:27:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepoFork(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
2017-06-17 00:49:45 -04:00
|
|
|
session := loginUser(t, "user1")
|
2017-06-06 22:27:49 -04:00
|
|
|
testRepoFork(t, session)
|
|
|
|
}
|