@@ -24,103 +24,59 @@ import (
24
24
25
25
func TestRepoCommits (t * testing.T ) {
26
26
defer tests .PrepareTestEnv (t )()
27
-
28
- session := loginUser (t , "user2" )
29
-
30
- // Request repository commits page
31
- req := NewRequest (t , "GET" , "/user2/repo1/commits/branch/master" )
32
- resp := session .MakeRequest (t , req , http .StatusOK )
33
-
34
- doc := NewHTMLParser (t , resp .Body )
35
- commitURL , exists := doc .doc .Find ("#commits-table .commit-id-short" ).Attr ("href" )
36
- assert .True (t , exists )
37
- assert .NotEmpty (t , commitURL )
38
- }
39
-
40
- func Test_ReposGitCommitListNotMaster (t * testing.T ) {
41
- defer tests .PrepareTestEnv (t )()
42
- session := loginUser (t , "user2" )
43
- req := NewRequest (t , "GET" , "/user2/repo16/commits/branch/master" )
44
- resp := session .MakeRequest (t , req , http .StatusOK )
45
-
46
- doc := NewHTMLParser (t , resp .Body )
47
- var commits []string
48
- doc .doc .Find ("#commits-table .commit-id-short" ).Each (func (i int , s * goquery.Selection ) {
49
- commitURL , _ := s .Attr ("href" )
50
- commits = append (commits , path .Base (commitURL ))
51
- })
52
- assert .Equal (t , []string {"69554a64c1e6030f051e5c3f94bfbd773cd6a324" , "27566bd5738fc8b4e3fef3c5e72cce608537bd95" , "5099b81332712fe655e34e8dd63574f503f61811" }, commits )
53
-
54
- var userHrefs []string
55
- doc .doc .Find ("#commits-table .author-wrapper" ).Each (func (i int , s * goquery.Selection ) {
56
- userHref , _ := s .Attr ("href" )
57
- userHrefs = append (userHrefs , userHref )
58
- })
59
- assert .Equal (t , []string {"/user2" , "/user21" , "/user2" }, userHrefs )
60
-
61
- // check last commit author wrapper
62
- req = NewRequest (t , "GET" , "/user2/repo16" )
63
- resp = session .MakeRequest (t , req , http .StatusOK )
64
-
65
- doc = NewHTMLParser (t , resp .Body )
66
- commits = []string {}
67
- doc .doc .Find (".latest-commit .commit-id-short" ).Each (func (i int , s * goquery.Selection ) {
68
- commitURL , _ := s .Attr ("href" )
69
- commits = append (commits , path .Base (commitURL ))
70
- })
71
- assert .Equal (t , []string {"69554a64c1e6030f051e5c3f94bfbd773cd6a324" }, commits )
72
-
73
- userHrefs = []string {}
74
- doc .doc .Find (".latest-commit .author-wrapper" ).Each (func (i int , s * goquery.Selection ) {
75
- userHref , _ := s .Attr ("href" )
76
- userHrefs = append (userHrefs , userHref )
77
- })
78
- assert .Equal (t , []string {"/user2" }, userHrefs )
79
- }
80
-
81
- func Test_ReposGitCommitListNoGiteaUser (t * testing.T ) {
82
- // Commits list with Gitea User has been tested in Test_ReposGitCommitListNotMaster
83
- defer tests .PrepareTestEnv (t )()
84
27
session := loginUser (t , "user2" )
85
28
86
- // check commits list for a repository with no gitea user
87
- req := NewRequest (t , "GET" , "/user2/repo1/commits/branch/master" )
88
- resp := session .MakeRequest (t , req , http .StatusOK )
89
-
90
- doc := NewHTMLParser (t , resp .Body )
91
- var commits []string
92
- doc .doc .Find ("#commits-table .commit-id-short" ).Each (func (i int , s * goquery.Selection ) {
93
- commitURL , _ := s .Attr ("href" )
94
- commits = append (commits , path .Base (commitURL ))
29
+ t .Run ("CommitList" , func (t * testing.T ) {
30
+ req := NewRequest (t , "GET" , "/user2/repo16/commits/branch/master" )
31
+ resp := session .MakeRequest (t , req , http .StatusOK )
32
+
33
+ var commits , userHrefs []string
34
+ doc := NewHTMLParser (t , resp .Body )
35
+ doc .doc .Find ("#commits-table .commit-id-short" ).Each (func (i int , s * goquery.Selection ) {
36
+ commits = append (commits , path .Base (s .AttrOr ("href" , "" )))
37
+ })
38
+ doc .doc .Find ("#commits-table .author-wrapper" ).Each (func (i int , s * goquery.Selection ) {
39
+ userHrefs = append (userHrefs , s .AttrOr ("href" , "" ))
40
+ })
41
+ assert .Equal (t , []string {"69554a64c1e6030f051e5c3f94bfbd773cd6a324" , "27566bd5738fc8b4e3fef3c5e72cce608537bd95" , "5099b81332712fe655e34e8dd63574f503f61811" }, commits )
42
+ assert .Equal (t , []string {"/user2" , "/user21" , "/user2" }, userHrefs )
95
43
})
96
- assert .Equal (t , []string {"65f1bf27bc3bf70f64657658635e66094edbcb4d" }, commits )
97
44
98
- var gitUsers []string
99
- doc .doc .Find ("#commits-table .author-wrapper" ).Each (func (i int , s * goquery.Selection ) {
100
- assert .Equal (t , "span" , goquery .NodeName (s ))
101
- gitUser := s .Text ()
102
- gitUsers = append (gitUsers , gitUser )
45
+ t .Run ("LastCommit" , func (t * testing.T ) {
46
+ req := NewRequest (t , "GET" , "/user2/repo16" )
47
+ resp := session .MakeRequest (t , req , http .StatusOK )
48
+ doc := NewHTMLParser (t , resp .Body )
49
+ commitHref := doc .doc .Find (".latest-commit .commit-id-short" ).AttrOr ("href" , "" )
50
+ authorHref := doc .doc .Find (".latest-commit .author-wrapper" ).AttrOr ("href" , "" )
51
+ assert .Equal (t , "/user2/repo16/commit/69554a64c1e6030f051e5c3f94bfbd773cd6a324" , commitHref )
52
+ assert .Equal (t , "/user2" , authorHref )
103
53
})
104
- assert .Equal (t , []string {"user1" }, gitUsers )
105
-
106
- // check last commit author wrapper
107
- req = NewRequest (t , "GET" , "/user2/repo1" )
108
- resp = session .MakeRequest (t , req , http .StatusOK )
109
54
110
- doc = NewHTMLParser (t , resp .Body )
111
- commits = []string {}
112
- doc .doc .Find (".latest-commit .commit-id-short" ).Each (func (i int , s * goquery.Selection ) {
113
- commitURL , _ := s .Attr ("href" )
114
- commits = append (commits , path .Base (commitURL ))
55
+ t .Run ("CommitListNonExistingCommiter" , func (t * testing.T ) {
56
+ // check the commit list for a repository with no gitea user
57
+ // * commit 985f0301dba5e7b34be866819cd15ad3d8f508ee (branch2)
58
+ // * Author: 6543 <6543@obermui.de>
59
+ req := NewRequest (t , "GET" , "/user2/repo1/commits/branch/branch2" )
60
+ resp := session .MakeRequest (t , req , http .StatusOK )
61
+
62
+ doc := NewHTMLParser (t , resp .Body )
63
+ commitHref := doc .doc .Find ("#commits-table tr:first-child .commit-id-short" ).AttrOr ("href" , "" )
64
+ assert .Equal (t , "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee" , commitHref )
65
+ authorElem := doc .doc .Find ("#commits-table tr:first-child .author-wrapper" )
66
+ assert .Equal (t , "6543" , authorElem .Text ())
67
+ assert .Equal (t , "span" , authorElem .Nodes [0 ].Data )
115
68
})
116
- assert .Equal (t , []string {"65f1bf27bc3bf70f64657658635e66094edbcb4d" }, commits )
117
69
118
- gitUsers = []string {}
119
- doc .doc .Find (".latest-commit .author-wrapper" ).Each (func (i int , s * goquery.Selection ) {
120
- assert .Equal (t , "span" , goquery .NodeName (s ))
121
- gitUsers = append (gitUsers , s .Text ())
70
+ t .Run ("LastCommitNonExistingCommiter" , func (t * testing.T ) {
71
+ req := NewRequest (t , "GET" , "/user2/repo1/src/branch/branch2" )
72
+ resp := session .MakeRequest (t , req , http .StatusOK )
73
+ doc := NewHTMLParser (t , resp .Body )
74
+ commitHref := doc .doc .Find (".latest-commit .commit-id-short" ).AttrOr ("href" , "" )
75
+ assert .Equal (t , "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee" , commitHref )
76
+ authorElem := doc .doc .Find (".latest-commit .author-wrapper" )
77
+ assert .Equal (t , "6543" , authorElem .Text ())
78
+ assert .Equal (t , "span" , authorElem .Nodes [0 ].Data )
122
79
})
123
- assert .Equal (t , []string {"user1" }, gitUsers )
124
80
}
125
81
126
82
func doTestRepoCommitWithStatus (t * testing.T , state string , classes ... string ) {
0 commit comments