@@ -7,8 +7,10 @@ package integrations
77import (
88 "fmt"
99 "net/http"
10+ "path"
1011 "strings"
1112 "testing"
13+ "time"
1214
1315 "code.gitea.io/gitea/modules/setting"
1416
@@ -29,12 +31,71 @@ func TestViewRepo(t *testing.T) {
2931 session .MakeRequest (t , req , http .StatusNotFound )
3032}
3133
32- func TestViewRepo2 (t * testing.T ) {
34+ func testViewRepo (t * testing.T ) {
3335 defer prepareTestEnv (t )()
3436
3537 req := NewRequest (t , "GET" , "/user3/repo3" )
3638 session := loginUser (t , "user2" )
37- session .MakeRequest (t , req , http .StatusOK )
39+ resp := session .MakeRequest (t , req , http .StatusOK )
40+
41+ htmlDoc := NewHTMLParser (t , resp .Body )
42+ files := htmlDoc .doc .Find ("#repo-files-table > TBODY > TR" )
43+
44+ type file struct {
45+ fileName string
46+ commitID string
47+ commitMsg string
48+ commitTime string
49+ }
50+
51+ var items []file
52+
53+ files .Each (func (i int , s * goquery.Selection ) {
54+ tds := s .Find ("td" )
55+ var f file
56+ tds .Each (func (i int , s * goquery.Selection ) {
57+ if i == 0 {
58+ f .fileName = strings .TrimSpace (s .Text ())
59+ } else if i == 1 {
60+ a := s .Find ("a" )
61+ f .commitMsg = strings .TrimSpace (a .Text ())
62+ l , _ := a .Attr ("href" )
63+ f .commitID = path .Base (l )
64+ }
65+ })
66+
67+ f .commitTime , _ = s .Find ("span.time-since" ).Attr ("title" )
68+ items = append (items , f )
69+ })
70+
71+ assert .EqualValues (t , []file {
72+ {
73+ fileName : "doc" ,
74+ commitID : "2a47ca4b614a9f5a43abbd5ad851a54a616ffee6" ,
75+ commitMsg : "init project" ,
76+ commitTime : time .Date (2017 , time .June , 14 , 13 , 54 , 21 , 0 , time .UTC ).Format (time .RFC1123 ),
77+ },
78+ {
79+ fileName : "README.md" ,
80+ commitID : "2a47ca4b614a9f5a43abbd5ad851a54a616ffee6" ,
81+ commitMsg : "init project" ,
82+ commitTime : time .Date (2017 , time .June , 14 , 13 , 54 , 21 , 0 , time .UTC ).Format (time .RFC1123 ),
83+ },
84+ }, items )
85+ }
86+
87+ func TestViewRepo2 (t * testing.T ) {
88+ // no last commit cache
89+ testViewRepo (t )
90+
91+ // enable last commit cache for all repositories
92+ oldCommitsCount := setting .CacheService .LastCommit .CommitsCount
93+ setting .CacheService .LastCommit .CommitsCount = 0
94+ // first view will not hit the cache
95+ testViewRepo (t )
96+ // second view will hit the cache
97+ testViewRepo (t )
98+ setting .CacheService .LastCommit .CommitsCount = oldCommitsCount
3899}
39100
40101func TestViewRepo3 (t * testing.T ) {
0 commit comments