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