Browse Source

fix golint error and rename func for suggestion. (#1997)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Bo-Yi Wu 2 years ago
parent
commit
90f9bb12c6

+ 2 - 2
integrations/change_default_branch_test.go

@@ -25,7 +25,7 @@ func TestChangeDefaultBranch(t *testing.T) {
25 25
 	req := NewRequest(t, "GET", branchesURL)
26 26
 	resp := session.MakeRequest(t, req)
27 27
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
28
-	doc := NewHtmlParser(t, resp.Body)
28
+	doc := NewHTMLParser(t, resp.Body)
29 29
 
30 30
 	req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
31 31
 		"_csrf":  doc.GetCSRF(),
@@ -39,7 +39,7 @@ func TestChangeDefaultBranch(t *testing.T) {
39 39
 	req = NewRequest(t, "GET", branchesURL)
40 40
 	resp = session.MakeRequest(t, req)
41 41
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
42
-	doc = NewHtmlParser(t, resp.Body)
42
+	doc = NewHTMLParser(t, resp.Body)
43 43
 
44 44
 	req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
45 45
 		"_csrf":  doc.GetInputValueByName("_csrf"),

+ 1 - 1
integrations/delete_user_test.go

@@ -22,7 +22,7 @@ func TestDeleteUser(t *testing.T) {
22 22
 	resp := session.MakeRequest(t, req)
23 23
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
24 24
 
25
-	doc := NewHtmlParser(t, resp.Body)
25
+	doc := NewHTMLParser(t, resp.Body)
26 26
 	req = NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{
27 27
 		"_csrf": doc.GetCSRF(),
28 28
 	})

+ 4 - 4
integrations/editor_test.go

@@ -22,7 +22,7 @@ func TestCreateFile(t *testing.T) {
22 22
 	resp := session.MakeRequest(t, req)
23 23
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
24 24
 
25
-	doc := NewHtmlParser(t, resp.Body)
25
+	doc := NewHTMLParser(t, resp.Body)
26 26
 	lastCommit := doc.GetInputValueByName("last_commit")
27 27
 	assert.NotEmpty(t, lastCommit)
28 28
 
@@ -49,7 +49,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
49 49
 	resp := session.MakeRequest(t, req)
50 50
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
51 51
 
52
-	doc := NewHtmlParser(t, resp.Body)
52
+	doc := NewHTMLParser(t, resp.Body)
53 53
 
54 54
 	// Change master branch to protected
55 55
 	req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{
@@ -70,7 +70,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
70 70
 	resp = session.MakeRequest(t, req)
71 71
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
72 72
 
73
-	doc = NewHtmlParser(t, resp.Body)
73
+	doc = NewHTMLParser(t, resp.Body)
74 74
 	lastCommit := doc.GetInputValueByName("last_commit")
75 75
 	assert.NotEmpty(t, lastCommit)
76 76
 
@@ -99,7 +99,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
99 99
 	resp := session.MakeRequest(t, req)
100 100
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
101 101
 
102
-	htmlDoc := NewHtmlParser(t, resp.Body)
102
+	htmlDoc := NewHTMLParser(t, resp.Body)
103 103
 	lastCommit := htmlDoc.GetInputValueByName("last_commit")
104 104
 	assert.NotEmpty(t, lastCommit)
105 105
 

+ 11 - 6
integrations/html_helper.go

@@ -12,26 +12,31 @@ import (
12 12
 	"github.com/stretchr/testify/assert"
13 13
 )
14 14
 
15
-type HtmlDoc struct {
15
+// HTMLDoc struct
16
+type HTMLDoc struct {
16 17
 	doc *goquery.Document
17 18
 }
18 19
 
19
-func NewHtmlParser(t testing.TB, content []byte) *HtmlDoc {
20
+// NewHTMLParser parse html file
21
+func NewHTMLParser(t testing.TB, content []byte) *HTMLDoc {
20 22
 	doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
21 23
 	assert.NoError(t, err)
22
-	return &HtmlDoc{doc: doc}
24
+	return &HTMLDoc{doc: doc}
23 25
 }
24 26
 
25
-func (doc *HtmlDoc) GetInputValueById(id string) string {
27
+// GetInputValueByID for get input value by id
28
+func (doc *HTMLDoc) GetInputValueByID(id string) string {
26 29
 	text, _ := doc.doc.Find("#" + id).Attr("value")
27 30
 	return text
28 31
 }
29 32
 
30
-func (doc *HtmlDoc) GetInputValueByName(name string) string {
33
+// GetInputValueByName for get input value by name
34
+func (doc *HTMLDoc) GetInputValueByName(name string) string {
31 35
 	text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
32 36
 	return text
33 37
 }
34 38
 
35
-func (doc *HtmlDoc) GetCSRF() string {
39
+// GetCSRF for get CSRC token value from input
40
+func (doc *HTMLDoc) GetCSRF() string {
36 41
 	return doc.GetInputValueByName("_csrf")
37 42
 }

+ 1 - 1
integrations/integration_test.go

@@ -167,7 +167,7 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession
167 167
 	resp := MakeRequest(req)
168 168
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
169 169
 
170
-	doc := NewHtmlParser(t, resp.Body)
170
+	doc := NewHTMLParser(t, resp.Body)
171 171
 	req = NewRequestWithValues(t, "POST", "/user/login", map[string]string{
172 172
 		"_csrf":     doc.GetCSRF(),
173 173
 		"user_name": userName,

+ 2 - 2
integrations/issue_test.go

@@ -17,7 +17,7 @@ import (
17 17
 	"github.com/stretchr/testify/assert"
18 18
 )
19 19
 
20
-func getIssuesSelection(htmlDoc *HtmlDoc) *goquery.Selection {
20
+func getIssuesSelection(htmlDoc *HTMLDoc) *goquery.Selection {
21 21
 	return htmlDoc.doc.Find(".issue.list").Find("li").Find(".title")
22 22
 }
23 23
 
@@ -50,7 +50,7 @@ func TestNoLoginViewIssuesSortByType(t *testing.T) {
50 50
 	resp := session.MakeRequest(t, req)
51 51
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
52 52
 
53
-	htmlDoc := NewHtmlParser(t, resp.Body)
53
+	htmlDoc := NewHTMLParser(t, resp.Body)
54 54
 	issuesSelection := getIssuesSelection(htmlDoc)
55 55
 	expectedNumIssues := models.GetCount(t,
56 56
 		&models.Issue{RepoID: repo.ID, PosterID: user.ID},

+ 1 - 1
integrations/pull_compare_test.go

@@ -18,7 +18,7 @@ func TestPullCompare(t *testing.T) {
18 18
 	req := NewRequest(t, "GET", "/user2/repo1/pulls")
19 19
 	resp := session.MakeRequest(t, req)
20 20
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
21
-	htmlDoc := NewHtmlParser(t, resp.Body)
21
+	htmlDoc := NewHTMLParser(t, resp.Body)
22 22
 	link, exists := htmlDoc.doc.Find(".navbar").Find(".ui.green.button").Attr("href")
23 23
 	assert.True(t, exists, "The template has changed")
24 24
 

+ 2 - 2
integrations/pull_create_test.go

@@ -18,7 +18,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
18 18
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
19 19
 
20 20
 	// Click the little green button to create a pull
21
-	htmlDoc := NewHtmlParser(t, resp.Body)
21
+	htmlDoc := NewHTMLParser(t, resp.Body)
22 22
 	link, exists := htmlDoc.doc.Find("button.ui.green.small.button").Parent().Attr("href")
23 23
 	assert.True(t, exists, "The template has changed")
24 24
 
@@ -27,7 +27,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
27 27
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
28 28
 
29 29
 	// Submit the form for creating the pull
30
-	htmlDoc = NewHtmlParser(t, resp.Body)
30
+	htmlDoc = NewHTMLParser(t, resp.Body)
31 31
 	link, exists = htmlDoc.doc.Find("form.ui.form").Attr("action")
32 32
 	assert.True(t, exists, "The template has changed")
33 33
 	req = NewRequestWithValues(t, "POST", link, map[string]string{

+ 1 - 1
integrations/pull_merge_test.go

@@ -19,7 +19,7 @@ func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum strin
19 19
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
20 20
 
21 21
 	// Click the little green button to craete a pull
22
-	htmlDoc := NewHtmlParser(t, resp.Body)
22
+	htmlDoc := NewHTMLParser(t, resp.Body)
23 23
 	link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
24 24
 	assert.True(t, exists, "The template has changed")
25 25
 	req = NewRequestWithValues(t, "POST", link, map[string]string{

+ 3 - 3
integrations/repo_commits_test.go

@@ -24,7 +24,7 @@ func TestRepoCommits(t *testing.T) {
24 24
 	resp := session.MakeRequest(t, req)
25 25
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
26 26
 
27
-	doc := NewHtmlParser(t, resp.Body)
27
+	doc := NewHTMLParser(t, resp.Body)
28 28
 	commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
29 29
 	assert.True(t, exists)
30 30
 	assert.NotEmpty(t, commitURL)
@@ -40,7 +40,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
40 40
 	resp := session.MakeRequest(t, req)
41 41
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
42 42
 
43
-	doc := NewHtmlParser(t, resp.Body)
43
+	doc := NewHTMLParser(t, resp.Body)
44 44
 	// Get first commit URL
45 45
 	commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
46 46
 	assert.True(t, exists)
@@ -64,7 +64,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
64 64
 	resp = session.MakeRequest(t, req)
65 65
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
66 66
 
67
-	doc = NewHtmlParser(t, resp.Body)
67
+	doc = NewHTMLParser(t, resp.Body)
68 68
 	// Check if commit status is displayed in message column
69 69
 	sel := doc.doc.Find("#commits-table tbody tr td.message i.commit-status")
70 70
 	assert.Equal(t, sel.Length(), 1)

+ 2 - 2
integrations/repo_fork_test.go

@@ -23,7 +23,7 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
23 23
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
24 24
 
25 25
 	// Step2: click the fork button
26
-	htmlDoc := NewHtmlParser(t, resp.Body)
26
+	htmlDoc := NewHTMLParser(t, resp.Body)
27 27
 	link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
28 28
 	assert.True(t, exists, "The template has changed")
29 29
 	req = NewRequest(t, "GET", link)
@@ -31,7 +31,7 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
31 31
 	assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
32 32
 
33 33
 	// Step3: fill the form of the forking
34
-	htmlDoc = NewHtmlParser(t, resp.Body)
34
+	htmlDoc = NewHTMLParser(t, resp.Body)
35 35
 	link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action")
36 36
 	assert.True(t, exists, "The template has changed")
37 37
 	req = NewRequestWithValues(t, "POST", link, map[string]string{