@@ -21,7 +21,7 @@ import (
21
21
"github.com/stretchr/testify/assert"
22
22
)
23
23
24
- func getExpectedContentsListResponseForContents (ref , refType string ) []* api.ContentsResponse {
24
+ func getExpectedContentsListResponseForContents (ref , refType , lastCommitSHA string ) []* api.ContentsResponse {
25
25
treePath := "README.md"
26
26
sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f"
27
27
selfURL := setting .AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=" + ref
@@ -30,15 +30,16 @@ func getExpectedContentsListResponseForContents(ref, refType string) []*api.Cont
30
30
downloadURL := setting .AppURL + "user2/repo1/raw/" + refType + "/" + ref + "/" + treePath
31
31
return []* api.ContentsResponse {
32
32
{
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 ,
42
43
Links : & api.FileLinksResponse {
43
44
Self : & selfURL ,
44
45
GitURL : & gitURL ,
@@ -94,7 +95,9 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
94
95
var contentsListResponse []* api.ContentsResponse
95
96
DecodeJSON (t , resp , & contentsListResponse )
96
97
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 ())
98
101
assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
99
102
100
103
// No ref
@@ -103,17 +106,22 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
103
106
resp = session .MakeRequest (t , req , http .StatusOK )
104
107
DecodeJSON (t , resp , & contentsListResponse )
105
108
assert .NotNil (t , contentsListResponse )
106
- expectedContentsListResponse = getExpectedContentsListResponseForContents (repo1 .DefaultBranch , refType )
109
+
110
+ expectedContentsListResponse = getExpectedContentsListResponseForContents (repo1 .DefaultBranch , refType , lastCommit .ID .String ())
107
111
assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
108
112
109
- // ref is the branch we created above in setup
113
+ // ref is the branch we created above in setup
110
114
ref = newBranch
111
115
refType = "branch"
112
116
req = NewRequestf (t , "GET" , "/api/v1/repos/%s/%s/contents/%s?ref=%s" , user2 .Name , repo1 .Name , treePath , ref )
113
117
resp = session .MakeRequest (t , req , http .StatusOK )
114
118
DecodeJSON (t , resp , & contentsListResponse )
115
119
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 ())
117
125
assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
118
126
119
127
// ref is the new tag we created above in setup
@@ -123,7 +131,11 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
123
131
resp = session .MakeRequest (t , req , http .StatusOK )
124
132
DecodeJSON (t , resp , & contentsListResponse )
125
133
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 ())
127
139
assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
128
140
129
141
// ref is a commit
@@ -133,7 +145,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
133
145
resp = session .MakeRequest (t , req , http .StatusOK )
134
146
DecodeJSON (t , resp , & contentsListResponse )
135
147
assert .NotNil (t , contentsListResponse )
136
- expectedContentsListResponse = getExpectedContentsListResponseForContents (ref , refType )
148
+ expectedContentsListResponse = getExpectedContentsListResponseForContents (ref , refType , commitID )
137
149
assert .EqualValues (t , expectedContentsListResponse , contentsListResponse )
138
150
139
151
// Test file contents a file with a bad ref
0 commit comments