@@ -5,13 +5,6 @@ package files
55
66import (
77 "testing"
8- "time"
9-
10- "code.gitea.io/gitea/models/unittest"
11- "code.gitea.io/gitea/modules/gitrepo"
12- "code.gitea.io/gitea/modules/setting"
13- api "code.gitea.io/gitea/modules/structs"
14- "code.gitea.io/gitea/services/contexttest"
158
169 "github.com/stretchr/testify/assert"
1710)
@@ -31,93 +24,3 @@ func TestCleanUploadFileName(t *testing.T) {
3124 assert .Equal (t , expectedCleanName , cleanName )
3225 })
3326}
34-
35- func getExpectedFileResponse () * api.FileResponse {
36- treePath := "README.md"
37- sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f"
38- encoding := "base64"
39- content := "IyByZXBvMQoKRGVzY3JpcHRpb24gZm9yIHJlcG8x"
40- selfURL := setting .AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master"
41- htmlURL := setting .AppURL + "user2/repo1/src/branch/master/" + treePath
42- gitURL := setting .AppURL + "api/v1/repos/user2/repo1/git/blobs/" + sha
43- downloadURL := setting .AppURL + "user2/repo1/raw/branch/master/" + treePath
44- return & api.FileResponse {
45- Content : & api.ContentsResponse {
46- Name : treePath ,
47- Path : treePath ,
48- SHA : sha ,
49- LastCommitSHA : "65f1bf27bc3bf70f64657658635e66094edbcb4d" ,
50- LastCommitterDate : time .Date (2017 , time .March , 19 , 16 , 47 , 59 , 0 , time .FixedZone ("" , - 14400 )),
51- LastAuthorDate : time .Date (2017 , time .March , 19 , 16 , 47 , 59 , 0 , time .FixedZone ("" , - 14400 )),
52- Type : "file" ,
53- Size : 30 ,
54- Encoding : & encoding ,
55- Content : & content ,
56- URL : & selfURL ,
57- HTMLURL : & htmlURL ,
58- GitURL : & gitURL ,
59- DownloadURL : & downloadURL ,
60- Links : & api.FileLinksResponse {
61- Self : & selfURL ,
62- GitURL : & gitURL ,
63- HTMLURL : & htmlURL ,
64- },
65- },
66- Commit : & api.FileCommitResponse {
67- CommitMeta : api.CommitMeta {
68- URL : "https://try.gitea.io/api/v1/repos/user2/repo1/git/commits/65f1bf27bc3bf70f64657658635e66094edbcb4d" ,
69- SHA : "65f1bf27bc3bf70f64657658635e66094edbcb4d" ,
70- },
71- HTMLURL : "https://try.gitea.io/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d" ,
72- Author : & api.CommitUser {
73- Identity : api.Identity {
74- Name : "user1" ,
75- 76- },
77- Date : "2017-03-19T20:47:59Z" ,
78- },
79- Committer : & api.CommitUser {
80- Identity : api.Identity {
81- Name : "Ethan Koenig" ,
82- 83- },
84- Date : "2017-03-19T20:47:59Z" ,
85- },
86- Parents : []* api.CommitMeta {},
87- Message : "Initial commit\n " ,
88- Tree : & api.CommitMeta {
89- URL : "https://try.gitea.io/api/v1/repos/user2/repo1/git/trees/2a2f1d4670728a2e10049e345bd7a276468beab6" ,
90- SHA : "2a2f1d4670728a2e10049e345bd7a276468beab6" ,
91- },
92- },
93- Verification : & api.PayloadCommitVerification {
94- Verified : false ,
95- Reason : "gpg.error.not_signed_commit" ,
96- Signature : "" ,
97- Payload : "" ,
98- },
99- }
100- }
101-
102- func TestGetFileResponseFromCommit (t * testing.T ) {
103- unittest .PrepareTestEnv (t )
104- ctx , _ := contexttest .MockContext (t , "user2/repo1" )
105- ctx .SetPathParam ("id" , "1" )
106- contexttest .LoadRepo (t , ctx , 1 )
107- contexttest .LoadRepoCommit (t , ctx )
108- contexttest .LoadUser (t , ctx , 2 )
109- contexttest .LoadGitRepo (t , ctx )
110- defer ctx .Repo .GitRepo .Close ()
111-
112- repo := ctx .Repo .Repository
113- branch := repo .DefaultBranch
114- treePath := "README.md"
115- gitRepo , _ := gitrepo .OpenRepository (ctx , repo )
116- defer gitRepo .Close ()
117- commit , _ := gitRepo .GetBranchCommit (branch )
118- expectedFileResponse := getExpectedFileResponse ()
119-
120- fileResponse , err := GetFileResponseFromCommit (ctx , repo , commit , branch , treePath )
121- assert .NoError (t , err )
122- assert .Equal (t , expectedFileResponse , fileResponse )
123- }
0 commit comments