|
|
|
@ -19,8 +19,7 @@ func TestCreateFile(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// Request editor page
|
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/_new/master/") |
|
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
|
|
|
|
|
doc := NewHTMLParser(t, resp.Body) |
|
|
|
|
lastCommit := doc.GetInputValueByName("last_commit") |
|
|
|
@ -34,8 +33,7 @@ func TestCreateFile(t *testing.T) { |
|
|
|
|
"content": "Content", |
|
|
|
|
"commit_choice": "direct", |
|
|
|
|
}) |
|
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusFound, resp.HeaderCode) |
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusFound) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestCreateFileOnProtectedBranch(t *testing.T) { |
|
|
|
@ -43,21 +41,14 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { |
|
|
|
|
|
|
|
|
|
session := loginUser(t, "user2") |
|
|
|
|
|
|
|
|
|
// Open repository branch settings
|
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/settings/branches") |
|
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
|
|
|
|
|
doc := NewHTMLParser(t, resp.Body) |
|
|
|
|
|
|
|
|
|
csrf := GetCSRF(t, session, "/user2/repo1/settings/branches") |
|
|
|
|
// Change master branch to protected
|
|
|
|
|
req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{ |
|
|
|
|
"_csrf": doc.GetCSRF(), |
|
|
|
|
req := NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{ |
|
|
|
|
"_csrf": csrf, |
|
|
|
|
"branchName": "master", |
|
|
|
|
"canPush": "true", |
|
|
|
|
}) |
|
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
// Check if master branch has been locked successfully
|
|
|
|
|
flashCookie := session.GetCookie("macaron_flash") |
|
|
|
|
assert.NotNil(t, flashCookie) |
|
|
|
@ -65,10 +56,9 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// Request editor page
|
|
|
|
|
req = NewRequest(t, "GET", "/user2/repo1/_new/master/") |
|
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
|
|
|
|
|
doc = NewHTMLParser(t, resp.Body) |
|
|
|
|
doc := NewHTMLParser(t, resp.Body) |
|
|
|
|
lastCommit := doc.GetInputValueByName("last_commit") |
|
|
|
|
assert.NotEmpty(t, lastCommit) |
|
|
|
|
|
|
|
|
@ -81,8 +71,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { |
|
|
|
|
"commit_choice": "direct", |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
// Check body for error message
|
|
|
|
|
assert.Contains(t, string(resp.Body), "Can not commit to protected branch 'master'.") |
|
|
|
|
} |
|
|
|
@ -93,8 +82,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa |
|
|
|
|
|
|
|
|
|
// Get to the 'edit this file' page
|
|
|
|
|
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath)) |
|
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body) |
|
|
|
|
lastCommit := htmlDoc.GetInputValueByName("last_commit") |
|
|
|
@ -110,13 +98,11 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa |
|
|
|
|
"commit_choice": "direct", |
|
|
|
|
}, |
|
|
|
|
) |
|
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusFound, resp.HeaderCode) |
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusFound) |
|
|
|
|
|
|
|
|
|
// Verify the change
|
|
|
|
|
req = NewRequest(t, "GET", path.Join(user, repo, "raw", branch, filePath)) |
|
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
assert.EqualValues(t, newContent, string(resp.Body)) |
|
|
|
|
|
|
|
|
|
return resp |
|
|
|
@ -128,8 +114,7 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra |
|
|
|
|
|
|
|
|
|
// Get to the 'edit this file' page
|
|
|
|
|
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath)) |
|
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body) |
|
|
|
|
lastCommit := htmlDoc.GetInputValueByName("last_commit") |
|
|
|
@ -146,13 +131,11 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra |
|
|
|
|
"new_branch_name": targetBranch, |
|
|
|
|
}, |
|
|
|
|
) |
|
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusFound, resp.HeaderCode) |
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusFound) |
|
|
|
|
|
|
|
|
|
// Verify the change
|
|
|
|
|
req = NewRequest(t, "GET", path.Join(user, repo, "raw", targetBranch, filePath)) |
|
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
assert.EqualValues(t, newContent, string(resp.Body)) |
|
|
|
|
|
|
|
|
|
return resp |
|
|
|
|