@@ -23,39 +23,59 @@ import (
23
23
24
24
func TestRepoCommits (t * testing.T ) {
25
25
defer tests .PrepareTestEnv (t )()
26
-
27
26
session := loginUser (t , "user2" )
28
27
29
- // Request repository commits page
30
- req := NewRequest (t , "GET" , "/user2/repo1/commits/branch/master" )
31
- resp := session .MakeRequest (t , req , http .StatusOK )
32
-
33
- doc := NewHTMLParser (t , resp .Body )
34
- commitURL , exists := doc .doc .Find ("#commits-table .commit-id-short" ).Attr ("href" )
35
- assert .True (t , exists )
36
- assert .NotEmpty (t , commitURL )
37
- }
28
+ t .Run ("CommitList" , func (t * testing.T ) {
29
+ req := NewRequest (t , "GET" , "/user2/repo16/commits/branch/master" )
30
+ resp := session .MakeRequest (t , req , http .StatusOK )
31
+
32
+ var commits , userHrefs []string
33
+ doc := NewHTMLParser (t , resp .Body )
34
+ doc .doc .Find ("#commits-table .commit-id-short" ).Each (func (i int , s * goquery.Selection ) {
35
+ commits = append (commits , path .Base (s .AttrOr ("href" , "" )))
36
+ })
37
+ doc .doc .Find ("#commits-table .author-wrapper" ).Each (func (i int , s * goquery.Selection ) {
38
+ userHrefs = append (userHrefs , s .AttrOr ("href" , "" ))
39
+ })
40
+ assert .Equal (t , []string {"69554a64c1e6030f051e5c3f94bfbd773cd6a324" , "27566bd5738fc8b4e3fef3c5e72cce608537bd95" , "5099b81332712fe655e34e8dd63574f503f61811" }, commits )
41
+ assert .Equal (t , []string {"/user2" , "/user21" , "/user2" }, userHrefs )
42
+ })
38
43
39
- func Test_ReposGitCommitListNotMaster (t * testing.T ) {
40
- defer tests .PrepareTestEnv (t )()
41
- session := loginUser (t , "user2" )
42
- req := NewRequest (t , "GET" , "/user2/repo16/commits/branch/master" )
43
- resp := session .MakeRequest (t , req , http .StatusOK )
44
+ t .Run ("LastCommit" , func (t * testing.T ) {
45
+ req := NewRequest (t , "GET" , "/user2/repo16" )
46
+ resp := session .MakeRequest (t , req , http .StatusOK )
47
+ doc := NewHTMLParser (t , resp .Body )
48
+ commitHref := doc .doc .Find (".latest-commit .commit-id-short" ).AttrOr ("href" , "" )
49
+ authorHref := doc .doc .Find (".latest-commit .author-wrapper" ).AttrOr ("href" , "" )
50
+ assert .Equal (t , "/user2/repo16/commit/69554a64c1e6030f051e5c3f94bfbd773cd6a324" , commitHref )
51
+ assert .Equal (t , "/user2" , authorHref )
52
+ })
44
53
45
- doc := NewHTMLParser (t , resp .Body )
46
- var commits []string
47
- doc .doc .Find ("#commits-table .commit-id-short" ).Each (func (i int , s * goquery.Selection ) {
48
- commitURL , _ := s .Attr ("href" )
49
- commits = append (commits , path .Base (commitURL ))
54
+ t .Run ("CommitListNonExistingCommiter" , func (t * testing.T ) {
55
+ // check the commit list for a repository with no gitea user
56
+ // * commit 985f0301dba5e7b34be866819cd15ad3d8f508ee (branch2)
57
+ // * Author: 6543 <[email protected] >
58
+ req := NewRequest (t , "GET" , "/user2/repo1/commits/branch/branch2" )
59
+ resp := session .MakeRequest (t , req , http .StatusOK )
60
+
61
+ doc := NewHTMLParser (t , resp .Body )
62
+ commitHref := doc .doc .Find ("#commits-table tr:first-child .commit-id-short" ).AttrOr ("href" , "" )
63
+ assert .Equal (t , "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee" , commitHref )
64
+ authorElem := doc .doc .Find ("#commits-table tr:first-child .author-wrapper" )
65
+ assert .Equal (t , "6543" , authorElem .Text ())
66
+ assert .Equal (t , "span" , authorElem .Nodes [0 ].Data )
50
67
})
51
- assert .Equal (t , []string {"69554a64c1e6030f051e5c3f94bfbd773cd6a324" , "27566bd5738fc8b4e3fef3c5e72cce608537bd95" , "5099b81332712fe655e34e8dd63574f503f61811" }, commits )
52
68
53
- var userHrefs []string
54
- doc .doc .Find ("#commits-table .author-wrapper" ).Each (func (i int , s * goquery.Selection ) {
55
- userHref , _ := s .Attr ("href" )
56
- userHrefs = append (userHrefs , userHref )
69
+ t .Run ("LastCommitNonExistingCommiter" , func (t * testing.T ) {
70
+ req := NewRequest (t , "GET" , "/user2/repo1/src/branch/branch2" )
71
+ resp := session .MakeRequest (t , req , http .StatusOK )
72
+ doc := NewHTMLParser (t , resp .Body )
73
+ commitHref := doc .doc .Find (".latest-commit .commit-id-short" ).AttrOr ("href" , "" )
74
+ assert .Equal (t , "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee" , commitHref )
75
+ authorElem := doc .doc .Find (".latest-commit .author-wrapper" )
76
+ assert .Equal (t , "6543" , authorElem .Text ())
77
+ assert .Equal (t , "span" , authorElem .Nodes [0 ].Data )
57
78
})
58
- assert .Equal (t , []string {"/user2" , "/user21" , "/user2" }, userHrefs )
59
79
}
60
80
61
81
func doTestRepoCommitWithStatus (t * testing.T , state string , classes ... string ) {
0 commit comments