mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 05:12:41 +01:00
Less verbose integration tests (#2123)
* Helper functions for intergration test boilerplate
This commit is contained in:
parent
5651cc7413
commit
f1adaef458
24 changed files with 121 additions and 222 deletions
|
@ -18,7 +18,7 @@ func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s", branchName)
|
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s", branchName)
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, NoExpectedStatus)
|
||||||
if !exists {
|
if !exists {
|
||||||
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
||||||
return
|
return
|
||||||
|
|
|
@ -26,8 +26,7 @@ func TestAPIListComments(t *testing.T) {
|
||||||
session := loginUser(t, repoOwner.Name)
|
session := loginUser(t, repoOwner.Name)
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments",
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments",
|
||||||
repoOwner.Name, repo.Name, issue.Index)
|
repoOwner.Name, repo.Name, issue.Index)
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
var comments []*api.Comment
|
var comments []*api.Comment
|
||||||
DecodeJSON(t, resp, &comments)
|
DecodeJSON(t, resp, &comments)
|
||||||
|
|
|
@ -29,8 +29,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
|
||||||
Labels: []int64{label.ID},
|
Labels: []int64{label.ID},
|
||||||
})
|
})
|
||||||
session := loginUser(t, owner.Name)
|
session := loginUser(t, owner.Name)
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
var apiLabels []*api.Label
|
var apiLabels []*api.Label
|
||||||
DecodeJSON(t, resp, &apiLabels)
|
DecodeJSON(t, resp, &apiLabels)
|
||||||
assert.Len(t, apiLabels, models.GetCount(t, &models.IssueLabel{IssueID: issue.ID}))
|
assert.Len(t, apiLabels, models.GetCount(t, &models.IssueLabel{IssueID: issue.ID}))
|
||||||
|
@ -52,8 +51,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
|
||||||
Labels: []int64{label.ID},
|
Labels: []int64{label.ID},
|
||||||
})
|
})
|
||||||
session := loginUser(t, owner.Name)
|
session := loginUser(t, owner.Name)
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
var apiLabels []*api.Label
|
var apiLabels []*api.Label
|
||||||
DecodeJSON(t, resp, &apiLabels)
|
DecodeJSON(t, resp, &apiLabels)
|
||||||
assert.Len(t, apiLabels, 1)
|
assert.Len(t, apiLabels, 1)
|
||||||
|
|
|
@ -24,8 +24,7 @@ func TestAPIListIssues(t *testing.T) {
|
||||||
session := loginUser(t, owner.Name)
|
session := loginUser(t, owner.Name)
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all",
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all",
|
||||||
owner.Name, repo.Name)
|
owner.Name, repo.Name)
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
var apiIssues []*api.Issue
|
var apiIssues []*api.Issue
|
||||||
DecodeJSON(t, resp, &apiIssues)
|
DecodeJSON(t, resp, &apiIssues)
|
||||||
assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID}))
|
assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID}))
|
||||||
|
@ -49,8 +48,7 @@ func TestAPICreateIssue(t *testing.T) {
|
||||||
Title: title,
|
Title: title,
|
||||||
Assignee: owner.Name,
|
Assignee: owner.Name,
|
||||||
})
|
})
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||||
assert.EqualValues(t, http.StatusCreated, resp.HeaderCode)
|
|
||||||
var apiIssue api.Issue
|
var apiIssue api.Issue
|
||||||
DecodeJSON(t, resp, &apiIssue)
|
DecodeJSON(t, resp, &apiIssue)
|
||||||
assert.Equal(t, apiIssue.Body, body)
|
assert.Equal(t, apiIssue.Body, body)
|
||||||
|
|
|
@ -21,8 +21,7 @@ func TestAPIViewPulls(t *testing.T) {
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls?state=all", owner.Name, repo.Name)
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls?state=all", owner.Name, repo.Name)
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
var pulls []*api.PullRequest
|
var pulls []*api.PullRequest
|
||||||
DecodeJSON(t, resp, &pulls)
|
DecodeJSON(t, resp, &pulls)
|
||||||
|
|
|
@ -7,22 +7,18 @@ package integrations
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAPIUserReposNotLogin(t *testing.T) {
|
func TestAPIUserReposNotLogin(t *testing.T) {
|
||||||
prepareTestEnv(t)
|
prepareTestEnv(t)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/api/v1/users/user2/repos")
|
req := NewRequest(t, "GET", "/api/v1/users/user2/repos")
|
||||||
resp := MakeRequest(req)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPISearchRepoNotLogin(t *testing.T) {
|
func TestAPISearchRepoNotLogin(t *testing.T) {
|
||||||
prepareTestEnv(t)
|
prepareTestEnv(t)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/api/v1/repos/search?q=Test")
|
req := NewRequest(t, "GET", "/api/v1/repos/search?q=Test")
|
||||||
resp := MakeRequest(req)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ func TestAPITeam(t *testing.T) {
|
||||||
|
|
||||||
session := loginUser(t, user.Name)
|
session := loginUser(t, user.Name)
|
||||||
req := NewRequestf(t, "GET", "/api/v1/teams/%d", teamUser.TeamID)
|
req := NewRequestf(t, "GET", "/api/v1/teams/%d", teamUser.TeamID)
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
var apiTeam api.Team
|
var apiTeam api.Team
|
||||||
DecodeJSON(t, resp, &apiTeam)
|
DecodeJSON(t, resp, &apiTeam)
|
||||||
|
|
|
@ -10,8 +10,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChangeDefaultBranch(t *testing.T) {
|
func TestChangeDefaultBranch(t *testing.T) {
|
||||||
|
@ -22,29 +20,19 @@ func TestChangeDefaultBranch(t *testing.T) {
|
||||||
session := loginUser(t, owner.Name)
|
session := loginUser(t, owner.Name)
|
||||||
branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
|
branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", branchesURL)
|
csrf := GetCSRF(t, session, branchesURL)
|
||||||
resp := session.MakeRequest(t, req)
|
req := NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
"_csrf": csrf,
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
|
||||||
|
|
||||||
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
|
||||||
"_csrf": doc.GetCSRF(),
|
|
||||||
"action": "default_branch",
|
"action": "default_branch",
|
||||||
"branch": "DefaultBranch",
|
"branch": "DefaultBranch",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
req = NewRequest(t, "GET", branchesURL)
|
|
||||||
resp = session.MakeRequest(t, req)
|
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
doc = NewHTMLParser(t, resp.Body)
|
|
||||||
|
|
||||||
|
csrf = GetCSRF(t, session, branchesURL)
|
||||||
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
||||||
"_csrf": doc.GetInputValueByName("_csrf"),
|
"_csrf": csrf,
|
||||||
"action": "default_branch",
|
"action": "default_branch",
|
||||||
"branch": "does_not_exist",
|
"branch": "does_not_exist",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
session.MakeRequest(t, req, http.StatusNotFound)
|
||||||
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDeleteUser(t *testing.T) {
|
func TestDeleteUser(t *testing.T) {
|
||||||
|
@ -18,16 +16,11 @@ func TestDeleteUser(t *testing.T) {
|
||||||
|
|
||||||
session := loginUser(t, "user1")
|
session := loginUser(t, "user1")
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/admin/users/8")
|
csrf := GetCSRF(t, session, "/admin/users/8")
|
||||||
resp := session.MakeRequest(t, req)
|
req := NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
"_csrf": csrf,
|
||||||
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
|
||||||
req = NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
|
|
||||||
"_csrf": doc.GetCSRF(),
|
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
models.AssertNotExistsBean(t, &models.User{ID: 8})
|
models.AssertNotExistsBean(t, &models.User{ID: 8})
|
||||||
models.CheckConsistencyFor(t, &models.User{})
|
models.CheckConsistencyFor(t, &models.User{})
|
||||||
|
|
|
@ -19,8 +19,7 @@ func TestCreateFile(t *testing.T) {
|
||||||
|
|
||||||
// Request editor page
|
// Request editor page
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/_new/master/")
|
req := NewRequest(t, "GET", "/user2/repo1/_new/master/")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
lastCommit := doc.GetInputValueByName("last_commit")
|
lastCommit := doc.GetInputValueByName("last_commit")
|
||||||
|
@ -34,8 +33,7 @@ func TestCreateFile(t *testing.T) {
|
||||||
"content": "Content",
|
"content": "Content",
|
||||||
"commit_choice": "direct",
|
"commit_choice": "direct",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateFileOnProtectedBranch(t *testing.T) {
|
func TestCreateFileOnProtectedBranch(t *testing.T) {
|
||||||
|
@ -43,21 +41,14 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
|
|
||||||
// Open repository branch settings
|
csrf := GetCSRF(t, session, "/user2/repo1/settings/branches")
|
||||||
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)
|
|
||||||
|
|
||||||
// Change master branch to protected
|
// Change master branch to protected
|
||||||
req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{
|
req := NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{
|
||||||
"_csrf": doc.GetCSRF(),
|
"_csrf": csrf,
|
||||||
"branchName": "master",
|
"branchName": "master",
|
||||||
"canPush": "true",
|
"canPush": "true",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
// Check if master branch has been locked successfully
|
// Check if master branch has been locked successfully
|
||||||
flashCookie := session.GetCookie("macaron_flash")
|
flashCookie := session.GetCookie("macaron_flash")
|
||||||
assert.NotNil(t, flashCookie)
|
assert.NotNil(t, flashCookie)
|
||||||
|
@ -65,10 +56,9 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
|
||||||
|
|
||||||
// Request editor page
|
// Request editor page
|
||||||
req = NewRequest(t, "GET", "/user2/repo1/_new/master/")
|
req = NewRequest(t, "GET", "/user2/repo1/_new/master/")
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
doc = NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
lastCommit := doc.GetInputValueByName("last_commit")
|
lastCommit := doc.GetInputValueByName("last_commit")
|
||||||
assert.NotEmpty(t, lastCommit)
|
assert.NotEmpty(t, lastCommit)
|
||||||
|
|
||||||
|
@ -81,8 +71,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
|
||||||
"commit_choice": "direct",
|
"commit_choice": "direct",
|
||||||
})
|
})
|
||||||
|
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
// Check body for error message
|
// Check body for error message
|
||||||
assert.Contains(t, string(resp.Body), "Can not commit to protected branch 'master'.")
|
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
|
// Get to the 'edit this file' page
|
||||||
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
|
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
lastCommit := htmlDoc.GetInputValueByName("last_commit")
|
lastCommit := htmlDoc.GetInputValueByName("last_commit")
|
||||||
|
@ -110,13 +98,11 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
|
||||||
"commit_choice": "direct",
|
"commit_choice": "direct",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Verify the change
|
// Verify the change
|
||||||
req = NewRequest(t, "GET", path.Join(user, repo, "raw", branch, filePath))
|
req = NewRequest(t, "GET", path.Join(user, repo, "raw", branch, filePath))
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
assert.EqualValues(t, newContent, string(resp.Body))
|
assert.EqualValues(t, newContent, string(resp.Body))
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
@ -128,8 +114,7 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
|
||||||
|
|
||||||
// Get to the 'edit this file' page
|
// Get to the 'edit this file' page
|
||||||
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
|
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
lastCommit := htmlDoc.GetInputValueByName("last_commit")
|
lastCommit := htmlDoc.GetInputValueByName("last_commit")
|
||||||
|
@ -146,13 +131,11 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
|
||||||
"new_branch_name": targetBranch,
|
"new_branch_name": targetBranch,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Verify the change
|
// Verify the change
|
||||||
req = NewRequest(t, "GET", path.Join(user, repo, "raw", targetBranch, filePath))
|
req = NewRequest(t, "GET", path.Join(user, repo, "raw", targetBranch, filePath))
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
assert.EqualValues(t, newContent, string(resp.Body))
|
assert.EqualValues(t, newContent, string(resp.Body))
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
|
@ -140,13 +140,13 @@ func (s *TestSession) GetCookie(name string) *http.Cookie {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TestSession) MakeRequest(t testing.TB, req *http.Request) *TestResponse {
|
func (s *TestSession) MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *TestResponse {
|
||||||
baseURL, err := url.Parse(setting.AppURL)
|
baseURL, err := url.Parse(setting.AppURL)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
for _, c := range s.jar.Cookies(baseURL) {
|
for _, c := range s.jar.Cookies(baseURL) {
|
||||||
req.AddCookie(c)
|
req.AddCookie(c)
|
||||||
}
|
}
|
||||||
resp := MakeRequest(req)
|
resp := MakeRequest(t, req, expectedStatus)
|
||||||
|
|
||||||
ch := http.Header{}
|
ch := http.Header{}
|
||||||
ch.Add("Cookie", strings.Join(resp.Headers["Set-Cookie"], ";"))
|
ch.Add("Cookie", strings.Join(resp.Headers["Set-Cookie"], ";"))
|
||||||
|
@ -164,8 +164,7 @@ func loginUser(t testing.TB, userName string) *TestSession {
|
||||||
|
|
||||||
func loginUserWithPassword(t testing.TB, userName, password string) *TestSession {
|
func loginUserWithPassword(t testing.TB, userName, password string) *TestSession {
|
||||||
req := NewRequest(t, "GET", "/user/login")
|
req := NewRequest(t, "GET", "/user/login")
|
||||||
resp := MakeRequest(req)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
req = NewRequestWithValues(t, "POST", "/user/login", map[string]string{
|
req = NewRequestWithValues(t, "POST", "/user/login", map[string]string{
|
||||||
|
@ -173,8 +172,7 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession
|
||||||
"user_name": userName,
|
"user_name": userName,
|
||||||
"password": password,
|
"password": password,
|
||||||
})
|
})
|
||||||
resp = MakeRequest(req)
|
resp = MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
ch := http.Header{}
|
ch := http.Header{}
|
||||||
ch.Add("Cookie", strings.Join(resp.Headers["Set-Cookie"], ";"))
|
ch.Add("Cookie", strings.Join(resp.Headers["Set-Cookie"], ";"))
|
||||||
|
@ -246,13 +244,18 @@ func NewRequestWithBody(t testing.TB, method, urlStr string, body io.Reader) *ht
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeRequest(req *http.Request) *TestResponse {
|
const NoExpectedStatus = -1
|
||||||
|
|
||||||
|
func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *TestResponse {
|
||||||
buffer := bytes.NewBuffer(nil)
|
buffer := bytes.NewBuffer(nil)
|
||||||
respWriter := &TestResponseWriter{
|
respWriter := &TestResponseWriter{
|
||||||
Writer: buffer,
|
Writer: buffer,
|
||||||
Headers: make(map[string][]string),
|
Headers: make(map[string][]string),
|
||||||
}
|
}
|
||||||
mac.ServeHTTP(respWriter, req)
|
mac.ServeHTTP(respWriter, req)
|
||||||
|
if expectedStatus != NoExpectedStatus {
|
||||||
|
assert.EqualValues(t, expectedStatus, respWriter.HeaderCode)
|
||||||
|
}
|
||||||
return &TestResponse{
|
return &TestResponse{
|
||||||
HeaderCode: respWriter.HeaderCode,
|
HeaderCode: respWriter.HeaderCode,
|
||||||
Body: buffer.Bytes(),
|
Body: buffer.Bytes(),
|
||||||
|
@ -264,3 +267,16 @@ func DecodeJSON(t testing.TB, resp *TestResponse, v interface{}) {
|
||||||
decoder := json.NewDecoder(bytes.NewBuffer(resp.Body))
|
decoder := json.NewDecoder(bytes.NewBuffer(resp.Body))
|
||||||
assert.NoError(t, decoder.Decode(v))
|
assert.NoError(t, decoder.Decode(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
|
||||||
|
req := NewRequest(t, "GET", urlStr)
|
||||||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
|
return doc.GetCSRF()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RedirectURL(t testing.TB, resp *TestResponse) string {
|
||||||
|
urlSlice := resp.Headers["Location"]
|
||||||
|
assert.NotEmpty(t, urlSlice, "No redirect URL founds")
|
||||||
|
return urlSlice[0]
|
||||||
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr,
|
||||||
t.Log(reqURL)
|
t.Log(reqURL)
|
||||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken))
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken))
|
||||||
|
|
||||||
resp := MakeRequest(req)
|
resp := MakeRequest(t, req, NoExpectedStatus)
|
||||||
if isErr {
|
if isErr {
|
||||||
assert.EqualValues(t, 500, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusInternalServerError, resp.HeaderCode)
|
||||||
} else {
|
} else {
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
var branch models.ProtectedBranch
|
var branch models.ProtectedBranch
|
||||||
|
|
|
@ -35,8 +35,7 @@ func TestNoLoginViewIssues(t *testing.T) {
|
||||||
prepareTestEnv(t)
|
prepareTestEnv(t)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/issues")
|
req := NewRequest(t, "GET", "/user2/repo1/issues")
|
||||||
resp := MakeRequest(req)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoLoginViewIssuesSortByType(t *testing.T) {
|
func TestNoLoginViewIssuesSortByType(t *testing.T) {
|
||||||
|
@ -48,8 +47,7 @@ func TestNoLoginViewIssuesSortByType(t *testing.T) {
|
||||||
|
|
||||||
session := loginUser(t, user.Name)
|
session := loginUser(t, user.Name)
|
||||||
req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by")
|
req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
issuesSelection := getIssuesSelection(htmlDoc)
|
issuesSelection := getIssuesSelection(htmlDoc)
|
||||||
|
@ -73,15 +71,13 @@ func TestNoLoginViewIssue(t *testing.T) {
|
||||||
prepareTestEnv(t)
|
prepareTestEnv(t)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/issues/1")
|
req := NewRequest(t, "GET", "/user2/repo1/issues/1")
|
||||||
resp := MakeRequest(req)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNewIssue(t *testing.T, session *TestSession, user, repo, title string) {
|
func testNewIssue(t *testing.T, session *TestSession, user, repo, title string) {
|
||||||
|
|
||||||
req := NewRequest(t, "GET", path.Join(user, repo, "issues", "new"))
|
req := NewRequest(t, "GET", path.Join(user, repo, "issues", "new"))
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
|
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
|
||||||
|
@ -90,14 +86,10 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title string)
|
||||||
"_csrf": htmlDoc.GetCSRF(),
|
"_csrf": htmlDoc.GetCSRF(),
|
||||||
"title": title,
|
"title": title,
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
redirectedURL := resp.Headers["Location"]
|
|
||||||
assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
|
|
||||||
|
|
||||||
req = NewRequest(t, "GET", redirectedURL[0])
|
req = NewRequest(t, "GET", RedirectURL(t, resp))
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewIssue(t *testing.T) {
|
func TestNewIssue(t *testing.T) {
|
||||||
|
|
|
@ -16,13 +16,12 @@ func TestPullCompare(t *testing.T) {
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/pulls")
|
req := NewRequest(t, "GET", "/user2/repo1/pulls")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
link, exists := htmlDoc.doc.Find(".navbar").Find(".ui.green.button").Attr("href")
|
link, exists := htmlDoc.doc.Find(".navbar").Find(".ui.green.button").Attr("href")
|
||||||
assert.True(t, exists, "The template has changed")
|
assert.True(t, exists, "The template has changed")
|
||||||
|
|
||||||
req = NewRequest(t, "GET", link)
|
req = NewRequest(t, "GET", link)
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@ import (
|
||||||
|
|
||||||
func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *TestResponse {
|
func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *TestResponse {
|
||||||
req := NewRequest(t, "GET", path.Join(user, repo))
|
req := NewRequest(t, "GET", path.Join(user, repo))
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Click the little green button to create a pull
|
// Click the little green button to create a pull
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
@ -27,8 +26,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
|
||||||
}
|
}
|
||||||
|
|
||||||
req = NewRequest(t, "GET", link)
|
req = NewRequest(t, "GET", link)
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Submit the form for creating the pull
|
// Submit the form for creating the pull
|
||||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||||
|
@ -38,8 +36,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
|
||||||
"_csrf": htmlDoc.GetCSRF(),
|
"_csrf": htmlDoc.GetCSRF(),
|
||||||
"title": "This is a pull title",
|
"title": "This is a pull title",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
//TODO check the redirected URL
|
//TODO check the redirected URL
|
||||||
|
|
||||||
|
|
|
@ -15,36 +15,32 @@ import (
|
||||||
|
|
||||||
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
|
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
|
||||||
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
|
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Click the little green button to craete a pull
|
// Click the little green button to create a pull
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
|
link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
|
||||||
assert.True(t, exists, "The template has changed")
|
assert.True(t, exists, "The template has changed")
|
||||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||||
"_csrf": htmlDoc.GetCSRF(),
|
"_csrf": htmlDoc.GetCSRF(),
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
|
func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
|
||||||
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
|
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Click the little green button to craete a pull
|
// Click the little green button to create a pull
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
link, exists := htmlDoc.doc.Find(".comments .merge .delete-button").Attr("data-url")
|
link, exists := htmlDoc.doc.Find(".comments .merge .delete-button").Attr("data-url")
|
||||||
assert.True(t, exists, "The template has changed")
|
assert.True(t, exists, "The template has changed")
|
||||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||||
"_csrf": htmlDoc.GetCSRF(),
|
"_csrf": htmlDoc.GetCSRF(),
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
@ -56,10 +52,8 @@ func TestPullMerge(t *testing.T) {
|
||||||
testEditFile(t, session, "user1", "repo1", "master", "README.md")
|
testEditFile(t, session, "user1", "repo1", "master", "README.md")
|
||||||
|
|
||||||
resp := testPullCreate(t, session, "user1", "repo1", "master")
|
resp := testPullCreate(t, session, "user1", "repo1", "master")
|
||||||
redirectedURL := resp.Headers["Location"]
|
|
||||||
assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
|
|
||||||
|
|
||||||
elem := strings.Split(redirectedURL[0], "/")
|
elem := strings.Split(RedirectURL(t, resp), "/")
|
||||||
assert.EqualValues(t, "pulls", elem[3])
|
assert.EqualValues(t, "pulls", elem[3])
|
||||||
testPullMerge(t, session, elem[1], elem[2], elem[4])
|
testPullMerge(t, session, elem[1], elem[2], elem[4])
|
||||||
}
|
}
|
||||||
|
@ -71,10 +65,8 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
|
||||||
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md")
|
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md")
|
||||||
|
|
||||||
resp := testPullCreate(t, session, "user1", "repo1", "feature/test")
|
resp := testPullCreate(t, session, "user1", "repo1", "feature/test")
|
||||||
redirectedURL := resp.Headers["Location"]
|
|
||||||
assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
|
|
||||||
|
|
||||||
elem := strings.Split(redirectedURL[0], "/")
|
elem := strings.Split(RedirectURL(t, resp), "/")
|
||||||
assert.EqualValues(t, "pulls", elem[3])
|
assert.EqualValues(t, "pulls", elem[3])
|
||||||
testPullMerge(t, session, elem[1], elem[2], elem[4])
|
testPullMerge(t, session, elem[1], elem[2], elem[4])
|
||||||
|
|
||||||
|
@ -92,8 +84,7 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
|
||||||
|
|
||||||
// Check branch deletion result
|
// Check branch deletion result
|
||||||
req := NewRequest(t, "GET", respJSON.Redirect)
|
req := NewRequest(t, "GET", respJSON.Redirect)
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
resultMsg := htmlDoc.doc.Find(".ui.message>p").Text()
|
resultMsg := htmlDoc.doc.Find(".ui.message>p").Text()
|
||||||
|
|
|
@ -15,8 +15,7 @@ import (
|
||||||
|
|
||||||
func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {
|
func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {
|
||||||
req := NewRequest(t, "GET", repoURL+"/releases/new")
|
req := NewRequest(t, "GET", repoURL+"/releases/new")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
link, exists := htmlDoc.doc.Find("form").Attr("action")
|
link, exists := htmlDoc.doc.Find("form").Attr("action")
|
||||||
|
@ -37,17 +36,14 @@ func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title st
|
||||||
}
|
}
|
||||||
req = NewRequestWithValues(t, "POST", link, postData)
|
req = NewRequestWithValues(t, "POST", link, postData)
|
||||||
|
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
redirectedURL := resp.Headers["Location"]
|
RedirectURL(t, resp) // check that redirect URL exists
|
||||||
assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, version, label string, count int) {
|
func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, version, label string, count int) {
|
||||||
req := NewRequest(t, "GET", repoURL+"/releases")
|
req := NewRequest(t, "GET", repoURL+"/releases")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
labelText := htmlDoc.doc.Find("#release-list > li .meta .label").First().Text()
|
labelText := htmlDoc.doc.Find("#release-list > li .meta .label").First().Text()
|
||||||
|
@ -64,16 +60,14 @@ func TestViewReleases(t *testing.T) {
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
||||||
resp := session.MakeRequest(t, req)
|
session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestViewReleasesNoLogin(t *testing.T) {
|
func TestViewReleasesNoLogin(t *testing.T) {
|
||||||
prepareTestEnv(t)
|
prepareTestEnv(t)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
||||||
resp := MakeRequest(req)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateRelease(t *testing.T) {
|
func TestCreateRelease(t *testing.T) {
|
||||||
|
|
|
@ -21,8 +21,7 @@ func TestRepoCommits(t *testing.T) {
|
||||||
|
|
||||||
// Request repository commits page
|
// Request repository commits page
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/commits/master")
|
req := NewRequest(t, "GET", "/user2/repo1/commits/master")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
|
commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
|
||||||
|
@ -37,8 +36,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||||
|
|
||||||
// Request repository commits page
|
// Request repository commits page
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/commits/master")
|
req := NewRequest(t, "GET", "/user2/repo1/commits/master")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
// Get first commit URL
|
// Get first commit URL
|
||||||
|
@ -56,12 +54,10 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusCreated)
|
||||||
assert.EqualValues(t, http.StatusCreated, resp.HeaderCode)
|
|
||||||
|
|
||||||
req = NewRequest(t, "GET", "/user2/repo1/commits/master")
|
req = NewRequest(t, "GET", "/user2/repo1/commits/master")
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
doc = NewHTMLParser(t, resp.Body)
|
doc = NewHTMLParser(t, resp.Body)
|
||||||
// Check if commit status is displayed in message column
|
// Check if commit status is displayed in message column
|
||||||
|
|
|
@ -14,21 +14,18 @@ import (
|
||||||
func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||||
// Step0: check the existence of the to-fork repo
|
// Step0: check the existence of the to-fork repo
|
||||||
req := NewRequest(t, "GET", "/user1/repo1")
|
req := NewRequest(t, "GET", "/user1/repo1")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusNotFound)
|
||||||
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Step1: go to the main page of repo
|
// Step1: go to the main page of repo
|
||||||
req = NewRequest(t, "GET", "/user2/repo1")
|
req = NewRequest(t, "GET", "/user2/repo1")
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Step2: click the fork button
|
// Step2: click the fork button
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
|
link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
|
||||||
assert.True(t, exists, "The template has changed")
|
assert.True(t, exists, "The template has changed")
|
||||||
req = NewRequest(t, "GET", link)
|
req = NewRequest(t, "GET", link)
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Step3: fill the form of the forking
|
// Step3: fill the form of the forking
|
||||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||||
|
@ -39,13 +36,11 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||||
"uid": "1",
|
"uid": "1",
|
||||||
"repo_name": "repo1",
|
"repo_name": "repo1",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
// Step4: check the existence of the forked repo
|
// Step4: check the existence of the forked repo
|
||||||
req = NewRequest(t, "GET", "/user1/repo1")
|
req = NewRequest(t, "GET", "/user1/repo1")
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,7 @@ import (
|
||||||
|
|
||||||
func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName string) *TestResponse {
|
func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName string) *TestResponse {
|
||||||
req := NewRequest(t, "GET", "/repo/migrate")
|
req := NewRequest(t, "GET", "/repo/migrate")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
|
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
|
||||||
|
@ -30,8 +29,7 @@ func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName str
|
||||||
"repo_name": repoName,
|
"repo_name": repoName,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,24 +7,19 @@ package integrations
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestViewRepo(t *testing.T) {
|
func TestViewRepo(t *testing.T) {
|
||||||
prepareTestEnv(t)
|
prepareTestEnv(t)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user2/repo1")
|
req := NewRequest(t, "GET", "/user2/repo1")
|
||||||
resp := MakeRequest(req)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
req = NewRequest(t, "GET", "/user3/repo3")
|
req = NewRequest(t, "GET", "/user3/repo3")
|
||||||
resp = MakeRequest(req)
|
MakeRequest(t, req, http.StatusNotFound)
|
||||||
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
session := loginUser(t, "user1")
|
session := loginUser(t, "user1")
|
||||||
resp = session.MakeRequest(t, req)
|
session.MakeRequest(t, req, http.StatusNotFound)
|
||||||
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestViewRepo2(t *testing.T) {
|
func TestViewRepo2(t *testing.T) {
|
||||||
|
@ -32,8 +27,7 @@ func TestViewRepo2(t *testing.T) {
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user3/repo3")
|
req := NewRequest(t, "GET", "/user3/repo3")
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
resp := session.MakeRequest(t, req)
|
session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestViewRepo3(t *testing.T) {
|
func TestViewRepo3(t *testing.T) {
|
||||||
|
@ -41,6 +35,5 @@ func TestViewRepo3(t *testing.T) {
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user3/repo3")
|
req := NewRequest(t, "GET", "/user3/repo3")
|
||||||
session := loginUser(t, "user3")
|
session := loginUser(t, "user3")
|
||||||
resp := session.MakeRequest(t, req)
|
session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSignup(t *testing.T) {
|
func TestSignup(t *testing.T) {
|
||||||
|
@ -24,11 +22,9 @@ func TestSignup(t *testing.T) {
|
||||||
"password": "examplePassword",
|
"password": "examplePassword",
|
||||||
"retype": "examplePassword",
|
"retype": "examplePassword",
|
||||||
})
|
})
|
||||||
resp := MakeRequest(req)
|
MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
// should be able to view new user's page
|
// should be able to view new user's page
|
||||||
req = NewRequest(t, "GET", "/exampleUser")
|
req = NewRequest(t, "GET", "/exampleUser")
|
||||||
resp = MakeRequest(req)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,27 +18,19 @@ func TestViewUser(t *testing.T) {
|
||||||
prepareTestEnv(t)
|
prepareTestEnv(t)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user2")
|
req := NewRequest(t, "GET", "/user2")
|
||||||
resp := MakeRequest(req)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenameUsername(t *testing.T) {
|
func TestRenameUsername(t *testing.T) {
|
||||||
prepareTestEnv(t)
|
prepareTestEnv(t)
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
||||||
req := NewRequest(t, "GET", "/user/settings")
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
||||||
resp := session.MakeRequest(t, req)
|
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
||||||
req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
|
||||||
"_csrf": htmlDoc.GetCSRF(),
|
|
||||||
"name": "newUsername",
|
"name": "newUsername",
|
||||||
"email": "user2@example.com",
|
"email": "user2@example.com",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
models.AssertExistsAndLoadBean(t, &models.User{Name: "newUsername"})
|
models.AssertExistsAndLoadBean(t, &models.User{Name: "newUsername"})
|
||||||
models.AssertNotExistsBean(t, &models.User{Name: "user2"})
|
models.AssertNotExistsBean(t, &models.User{Name: "user2"})
|
||||||
|
@ -58,19 +50,14 @@ func TestRenameInvalidUsername(t *testing.T) {
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
for _, invalidUsername := range invalidUsernames {
|
for _, invalidUsername := range invalidUsernames {
|
||||||
t.Logf("Testing username %s", invalidUsername)
|
t.Logf("Testing username %s", invalidUsername)
|
||||||
req := NewRequest(t, "GET", "/user/settings")
|
|
||||||
resp := session.MakeRequest(t, req)
|
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
||||||
req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
||||||
"_csrf": htmlDoc.GetCSRF(),
|
|
||||||
"name": invalidUsername,
|
"name": invalidUsername,
|
||||||
"email": "user2@example.com",
|
"email": "user2@example.com",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
|
||||||
assert.Contains(t,
|
assert.Contains(t,
|
||||||
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
||||||
i18n.Tr("en", "form.alpha_dash_dot_error"),
|
i18n.Tr("en", "form.alpha_dash_dot_error"),
|
||||||
|
@ -92,23 +79,16 @@ func TestRenameReservedUsername(t *testing.T) {
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
for _, reservedUsername := range reservedUsernames {
|
for _, reservedUsername := range reservedUsernames {
|
||||||
t.Logf("Testing username %s", reservedUsername)
|
t.Logf("Testing username %s", reservedUsername)
|
||||||
req := NewRequest(t, "GET", "/user/settings")
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
||||||
resp := session.MakeRequest(t, req)
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
||||||
req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
|
||||||
"_csrf": htmlDoc.GetCSRF(),
|
|
||||||
"name": reservedUsername,
|
"name": reservedUsername,
|
||||||
"email": "user2@example.com",
|
"email": "user2@example.com",
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req, http.StatusFound)
|
||||||
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
|
|
||||||
|
|
||||||
req = NewRequest(t, "GET", "/user/settings")
|
req = NewRequest(t, "GET", RedirectURL(t, resp))
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
|
||||||
assert.Contains(t,
|
assert.Contains(t,
|
||||||
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
||||||
i18n.Tr("en", "user.newName_reserved"),
|
i18n.Tr("en", "user.newName_reserved"),
|
||||||
|
|
|
@ -19,8 +19,7 @@ func TestVersion(t *testing.T) {
|
||||||
|
|
||||||
setting.AppVer = "1.1.0+dev"
|
setting.AppVer = "1.1.0+dev"
|
||||||
req := NewRequest(t, "GET", "/api/v1/version")
|
req := NewRequest(t, "GET", "/api/v1/version")
|
||||||
resp := MakeRequest(req)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
||||||
|
|
||||||
var version gitea.ServerVersion
|
var version gitea.ServerVersion
|
||||||
DecodeJSON(t, resp, &version)
|
DecodeJSON(t, resp, &version)
|
||||||
|
|
Loading…
Reference in a new issue