fix golint error and rename func for suggestion. (#1997)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
6233e88f7f
commit
90f9bb12c6
11 changed files with 30 additions and 25 deletions
|
@ -25,7 +25,7 @@ func TestChangeDefaultBranch(t *testing.T) {
|
||||||
req := NewRequest(t, "GET", branchesURL)
|
req := NewRequest(t, "GET", branchesURL)
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
doc := NewHtmlParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
||||||
"_csrf": doc.GetCSRF(),
|
"_csrf": doc.GetCSRF(),
|
||||||
|
@ -39,7 +39,7 @@ func TestChangeDefaultBranch(t *testing.T) {
|
||||||
req = NewRequest(t, "GET", branchesURL)
|
req = NewRequest(t, "GET", branchesURL)
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
doc = NewHtmlParser(t, resp.Body)
|
doc = NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
||||||
"_csrf": doc.GetInputValueByName("_csrf"),
|
"_csrf": doc.GetInputValueByName("_csrf"),
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestDeleteUser(t *testing.T) {
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
|
|
||||||
doc := NewHtmlParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
req = NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
|
req = NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
|
||||||
"_csrf": doc.GetCSRF(),
|
"_csrf": doc.GetCSRF(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestCreateFile(t *testing.T) {
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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)
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
|
|
||||||
doc := NewHtmlParser(t, resp.Body)
|
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{
|
||||||
|
@ -70,7 +70,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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)
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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")
|
||||||
assert.NotEmpty(t, lastCommit)
|
assert.NotEmpty(t, lastCommit)
|
||||||
|
|
||||||
|
|
|
@ -12,26 +12,31 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HtmlDoc struct {
|
// HTMLDoc struct
|
||||||
|
type HTMLDoc struct {
|
||||||
doc *goquery.Document
|
doc *goquery.Document
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHtmlParser(t testing.TB, content []byte) *HtmlDoc {
|
// NewHTMLParser parse html file
|
||||||
|
func NewHTMLParser(t testing.TB, content []byte) *HTMLDoc {
|
||||||
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
|
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return &HtmlDoc{doc: doc}
|
return &HTMLDoc{doc: doc}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (doc *HtmlDoc) GetInputValueById(id string) string {
|
// GetInputValueByID for get input value by id
|
||||||
|
func (doc *HTMLDoc) GetInputValueByID(id string) string {
|
||||||
text, _ := doc.doc.Find("#" + id).Attr("value")
|
text, _ := doc.doc.Find("#" + id).Attr("value")
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (doc *HtmlDoc) GetInputValueByName(name string) string {
|
// GetInputValueByName for get input value by name
|
||||||
|
func (doc *HTMLDoc) GetInputValueByName(name string) string {
|
||||||
text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
|
text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (doc *HtmlDoc) GetCSRF() string {
|
// GetCSRF for get CSRC token value from input
|
||||||
|
func (doc *HTMLDoc) GetCSRF() string {
|
||||||
return doc.GetInputValueByName("_csrf")
|
return doc.GetInputValueByName("_csrf")
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession
|
||||||
resp := MakeRequest(req)
|
resp := MakeRequest(req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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{
|
||||||
"_csrf": doc.GetCSRF(),
|
"_csrf": doc.GetCSRF(),
|
||||||
"user_name": userName,
|
"user_name": userName,
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getIssuesSelection(htmlDoc *HtmlDoc) *goquery.Selection {
|
func getIssuesSelection(htmlDoc *HTMLDoc) *goquery.Selection {
|
||||||
return htmlDoc.doc.Find(".issue.list").Find("li").Find(".title")
|
return htmlDoc.doc.Find(".issue.list").Find("li").Find(".title")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func TestNoLoginViewIssuesSortByType(t *testing.T) {
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
|
|
||||||
htmlDoc := NewHtmlParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
issuesSelection := getIssuesSelection(htmlDoc)
|
issuesSelection := getIssuesSelection(htmlDoc)
|
||||||
expectedNumIssues := models.GetCount(t,
|
expectedNumIssues := models.GetCount(t,
|
||||||
&models.Issue{RepoID: repo.ID, PosterID: user.ID},
|
&models.Issue{RepoID: repo.ID, PosterID: user.ID},
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestPullCompare(t *testing.T) {
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/pulls")
|
req := NewRequest(t, "GET", "/user2/repo1/pulls")
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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")
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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)
|
||||||
link, exists := htmlDoc.doc.Find("button.ui.green.small.button").Parent().Attr("href")
|
link, exists := htmlDoc.doc.Find("button.ui.green.small.button").Parent().Attr("href")
|
||||||
assert.True(t, exists, "The template has changed")
|
assert.True(t, exists, "The template has changed")
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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)
|
||||||
link, exists = htmlDoc.doc.Find("form.ui.form").Attr("action")
|
link, exists = htmlDoc.doc.Find("form.ui.form").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{
|
||||||
|
|
|
@ -19,7 +19,7 @@ func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum strin
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
|
|
||||||
// Click the little green button to craete a pull
|
// Click the little green button to craete 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{
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestRepoCommits(t *testing.T) {
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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")
|
||||||
assert.True(t, exists)
|
assert.True(t, exists)
|
||||||
assert.NotEmpty(t, commitURL)
|
assert.NotEmpty(t, commitURL)
|
||||||
|
@ -40,7 +40,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||||
resp := session.MakeRequest(t, req)
|
resp := session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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
|
||||||
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")
|
||||||
assert.True(t, exists)
|
assert.True(t, exists)
|
||||||
|
@ -64,7 +64,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||||
resp = session.MakeRequest(t, req)
|
resp = session.MakeRequest(t, req)
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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
|
||||||
sel := doc.doc.Find("#commits-table tbody tr td.message i.commit-status")
|
sel := doc.doc.Find("#commits-table tbody tr td.message i.commit-status")
|
||||||
assert.Equal(t, sel.Length(), 1)
|
assert.Equal(t, sel.Length(), 1)
|
||||||
|
|
|
@ -23,7 +23,7 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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)
|
||||||
|
@ -31,7 +31,7 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||||
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
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)
|
||||||
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action")
|
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").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{
|
||||||
|
|
Reference in a new issue