Skip to content

Commit e2473ba

Browse files
committed
fix TestGetContentsOrListForDir
1 parent cb42d29 commit e2473ba

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

services/repository/files/content_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,36 @@ func TestMain(m *testing.M) {
2020
unittest.MainTest(m)
2121
}
2222

23+
func getExpectedGiteaContentsResponse() *api.ContentsResponse {
24+
treePath := ".gitea"
25+
sha := "b5f7dda5e39c1eef0d4da9c20b7d8322daa7add5"
26+
encoding := ""
27+
content := ""
28+
selfURL := "https://try.gitea.io/api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master"
29+
htmlURL := "https://try.gitea.io/user2/repo1/src/branch/master/" + treePath
30+
gitURL := "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/" + sha
31+
downloadURL := "https://try.gitea.io/user2/repo1/raw/branch/master/" + treePath
32+
return &api.ContentsResponse{
33+
Name: treePath,
34+
Path: treePath,
35+
SHA: sha,
36+
LastCommitSHA: "94dc45d6ec51090b36c4d5bd5d9e6f5a70da9edf",
37+
Type: "dir",
38+
Size: 0,
39+
Encoding: &encoding,
40+
Content: &content,
41+
URL: &selfURL,
42+
HTMLURL: &htmlURL,
43+
GitURL: &gitURL,
44+
DownloadURL: &downloadURL,
45+
Links: &api.FileLinksResponse{
46+
Self: &selfURL,
47+
GitURL: &gitURL,
48+
HTMLURL: &htmlURL,
49+
},
50+
}
51+
}
52+
2353
func getExpectedReadmeContentsResponse() *api.ContentsResponse {
2454
treePath := "README.md"
2555
sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f"
@@ -32,7 +62,7 @@ func getExpectedReadmeContentsResponse() *api.ContentsResponse {
3262
return &api.ContentsResponse{
3363
Name: treePath,
3464
Path: treePath,
35-
SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f",
65+
SHA: sha,
3666
LastCommitSHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
3767
Type: "file",
3868
Size: 30,
@@ -96,7 +126,15 @@ func TestGetContentsOrListForDir(t *testing.T) {
96126
readmeContentsResponse.Encoding = nil
97127
readmeContentsResponse.Content = nil
98128

129+
giteaContentsResponse := getExpectedGiteaContentsResponse()
130+
// because will be in a list, doesn't have encoding and content
131+
giteaContentsResponse.Encoding = nil
132+
giteaContentsResponse.Content = nil
133+
// because .gitea is a directory, doesn't have download url
134+
giteaContentsResponse.DownloadURL = nil
135+
99136
expectedContentsListResponse := []*api.ContentsResponse{
137+
giteaContentsResponse,
100138
readmeContentsResponse,
101139
}
102140

0 commit comments

Comments
 (0)