@@ -21,7 +21,7 @@ import (
2121 "github.com/stretchr/testify/assert"
2222)
2323
24- func getExpectedContentsListResponseForContents (ref , refType string ) []* api.ContentsResponse {
24+ func getExpectedContentsListResponseForContents (ref , refType , lastCommitSHA string ) []* api.ContentsResponse {
2525 treePath := "README.md"
2626 sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f"
2727 selfURL := setting .AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=" + ref
@@ -30,15 +30,16 @@ func getExpectedContentsListResponseForContents(ref, refType string) []*api.Cont
3030 downloadURL := setting .AppURL + "user2/repo1/raw/" + refType + "/" + ref + "/" + treePath
3131 return []* api.ContentsResponse {
3232 {
33- Name : filepath .Base (treePath ),
34- Path : treePath ,
35- SHA : sha ,
36- Type : "file" ,
37- Size : 30 ,
38- URL : & selfURL ,
39- HTMLURL : & htmlURL ,
40- GitURL : & gitURL ,
41- DownloadURL : & downloadURL ,
33+ Name : filepath .Base (treePath ),
34+ Path : treePath ,
35+ SHA : sha ,
36+ LastCommitSHA : lastCommitSHA ,
37+ Type : "file" ,
38+ Size : 30 ,
39+ URL : & selfURL ,
40+ HTMLURL : & htmlURL ,
41+ GitURL : & gitURL ,
42+ DownloadURL : & downloadURL ,
4243 Links : & api.FileLinksResponse {
4344 Self : & selfURL ,
4445 GitURL : & gitURL ,
@@ -94,7 +95,9 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
9495 var contentsListResponse []* api.ContentsResponse
9596 DecodeJSON (t , resp , & contentsListResponse )
9697 assert .NotNil (t , contentsListResponse )
97- expectedContentsListResponse := getExpectedContentsListResponseForContents (ref , refType )
98+ lastCommit , err := gitRepo .GetCommitByPath ("README.md" )
99+ assert .NoError (t , err )
100+ expectedContentsListResponse := getExpectedContentsListResponseForContents (ref , refType , lastCommit .ID .String ())
98101 assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
99102
100103 // No ref
@@ -103,17 +106,22 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
103106 resp = session .MakeRequest (t , req , http .StatusOK )
104107 DecodeJSON (t , resp , & contentsListResponse )
105108 assert .NotNil (t , contentsListResponse )
106- expectedContentsListResponse = getExpectedContentsListResponseForContents (repo1 .DefaultBranch , refType )
109+
110+ expectedContentsListResponse = getExpectedContentsListResponseForContents (repo1 .DefaultBranch , refType , lastCommit .ID .String ())
107111 assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
108112
109- // ref is the branch we created above in setup
113+ // ref is the branch we created above in setup
110114 ref = newBranch
111115 refType = "branch"
112116 req = NewRequestf (t , "GET" , "/api/v1/repos/%s/%s/contents/%s?ref=%s" , user2 .Name , repo1 .Name , treePath , ref )
113117 resp = session .MakeRequest (t , req , http .StatusOK )
114118 DecodeJSON (t , resp , & contentsListResponse )
115119 assert .NotNil (t , contentsListResponse )
116- expectedContentsListResponse = getExpectedContentsListResponseForContents (ref , refType )
120+ branchCommit , err := gitRepo .GetBranchCommit (ref )
121+ assert .NoError (t , err )
122+ lastCommit , err = branchCommit .GetCommitByPath ("README.md" )
123+ assert .NoError (t , err )
124+ expectedContentsListResponse = getExpectedContentsListResponseForContents (ref , refType , lastCommit .ID .String ())
117125 assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
118126
119127 // ref is the new tag we created above in setup
@@ -123,7 +131,11 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
123131 resp = session .MakeRequest (t , req , http .StatusOK )
124132 DecodeJSON (t , resp , & contentsListResponse )
125133 assert .NotNil (t , contentsListResponse )
126- expectedContentsListResponse = getExpectedContentsListResponseForContents (ref , refType )
134+ tagCommit , err := gitRepo .GetTagCommit (ref )
135+ assert .NoError (t , err )
136+ lastCommit , err = tagCommit .GetCommitByPath ("README.md" )
137+ assert .NoError (t , err )
138+ expectedContentsListResponse = getExpectedContentsListResponseForContents (ref , refType , lastCommit .ID .String ())
127139 assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
128140
129141 // ref is a commit
@@ -133,7 +145,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
133145 resp = session .MakeRequest (t , req , http .StatusOK )
134146 DecodeJSON (t , resp , & contentsListResponse )
135147 assert .NotNil (t , contentsListResponse )
136- expectedContentsListResponse = getExpectedContentsListResponseForContents (ref , refType )
148+ expectedContentsListResponse = getExpectedContentsListResponseForContents (ref , refType , commitID )
137149 assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
138150
139151 // Test file contents a file with a bad ref
0 commit comments