2017-06-07 05:27:49 +03: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 14:20:39 +03:00
|
|
|
func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
2017-06-07 05:27:49 +03:00
|
|
|
// Step0: check the existence of the to-fork repo
|
2017-06-10 03:41:36 +03:00
|
|
|
req := NewRequest(t, "GET", "/user1/repo1")
|
2017-06-07 05:27:49 +03:00
|
|
|
resp := session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step1: go to the main page of repo
|
2017-06-10 03:41:36 +03:00
|
|
|
req = NewRequest(t, "GET", "/user2/repo1")
|
2017-06-07 05:27:49 +03:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step2: click the fork button
|
2017-06-17 07:49:45 +03:00
|
|
|
htmlDoc := NewHtmlParser(t, resp.Body)
|
2017-06-07 05:27:49 +03: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 03:41:36 +03:00
|
|
|
req = NewRequest(t, "GET", link)
|
2017-06-07 05:27:49 +03:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
|
|
|
|
// Step3: fill the form of the forking
|
2017-06-17 07:49:45 +03:00
|
|
|
htmlDoc = NewHtmlParser(t, resp.Body)
|
2017-06-07 05:27:49 +03: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 07:49:45 +03:00
|
|
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"uid": "1",
|
|
|
|
"repo_name": "repo1",
|
|
|
|
})
|
2017-06-07 05:27:49 +03: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 03:41:36 +03:00
|
|
|
req = NewRequest(t, "GET", "/user1/repo1")
|
2017-06-07 05:27:49 +03:00
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
2017-06-15 14:20:39 +03:00
|
|
|
|
|
|
|
return resp
|
2017-06-07 05:27:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepoFork(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
2017-06-17 07:49:45 +03:00
|
|
|
session := loginUser(t, "user1")
|
2017-06-07 05:27:49 +03:00
|
|
|
testRepoFork(t, session)
|
|
|
|
}
|