@@ -8,13 +8,16 @@ import (
8
8
"crypto/rand"
9
9
"fmt"
10
10
"io/ioutil"
11
+ "net/http"
11
12
"net/url"
12
13
"os"
14
+ "path"
13
15
"path/filepath"
14
16
"testing"
15
17
"time"
16
18
17
19
"code.gitea.io/git"
20
+ "code.gitea.io/gitea/models"
18
21
19
22
"github.com/stretchr/testify/assert"
20
23
)
@@ -39,6 +42,8 @@ func testGit(t *testing.T, u *url.URL) {
39
42
httpContext .Reponame = "repo-tmp-17"
40
43
41
44
dstPath , err := ioutil .TempDir ("" , httpContext .Reponame )
45
+ var little , big , littleLFS , bigLFS string
46
+
42
47
assert .NoError (t , err )
43
48
defer os .RemoveAll (dstPath )
44
49
t .Run ("Standard" , func (t * testing.T ) {
@@ -53,10 +58,10 @@ func testGit(t *testing.T, u *url.URL) {
53
58
54
59
t .Run ("PushCommit" , func (t * testing.T ) {
55
60
t .Run ("Little" , func (t * testing.T ) {
56
- commitAndPush (t , littleSize , dstPath )
61
+ little = commitAndPush (t , littleSize , dstPath )
57
62
})
58
63
t .Run ("Big" , func (t * testing.T ) {
59
- commitAndPush (t , bigSize , dstPath )
64
+ big = commitAndPush (t , bigSize , dstPath )
60
65
})
61
66
})
62
67
})
@@ -71,16 +76,60 @@ func testGit(t *testing.T, u *url.URL) {
71
76
assert .NoError (t , err )
72
77
73
78
t .Run ("Little" , func (t * testing.T ) {
74
- commitAndPush (t , littleSize , dstPath )
79
+ littleLFS = commitAndPush (t , littleSize , dstPath )
75
80
})
76
81
t .Run ("Big" , func (t * testing.T ) {
77
- commitAndPush (t , bigSize , dstPath )
82
+ bigLFS = commitAndPush (t , bigSize , dstPath )
78
83
})
79
84
})
80
85
t .Run ("Locks" , func (t * testing.T ) {
81
86
lockTest (t , u .String (), dstPath )
82
87
})
83
88
})
89
+ t .Run ("Raw" , func (t * testing.T ) {
90
+ session := loginUser (t , "user2" )
91
+
92
+ // Request raw paths
93
+ req := NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-17/raw/branch/master/" , little ))
94
+ resp := session .MakeRequest (t , req , http .StatusOK )
95
+ assert .Equal (t , littleSize , resp .Body .Len ())
96
+
97
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-17/raw/branch/master/" , big ))
98
+ nilResp := session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
99
+ assert .Equal (t , bigSize , nilResp .Length )
100
+
101
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-17/raw/branch/master/" , littleLFS ))
102
+ resp = session .MakeRequest (t , req , http .StatusOK )
103
+ assert .NotEqual (t , littleSize , resp .Body .Len ())
104
+ assert .Contains (t , resp .Body .String (), models .LFSMetaFileIdentifier )
105
+
106
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-17/raw/branch/master/" , bigLFS ))
107
+ resp = session .MakeRequest (t , req , http .StatusOK )
108
+ assert .NotEqual (t , bigSize , resp .Body .Len ())
109
+ assert .Contains (t , resp .Body .String (), models .LFSMetaFileIdentifier )
110
+
111
+ })
112
+ t .Run ("Media" , func (t * testing.T ) {
113
+ session := loginUser (t , "user2" )
114
+
115
+ // Request media paths
116
+ req := NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-17/media/branch/master/" , little ))
117
+ resp := session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
118
+ assert .Equal (t , littleSize , resp .Length )
119
+
120
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-17/media/branch/master/" , big ))
121
+ resp = session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
122
+ assert .Equal (t , bigSize , resp .Length )
123
+
124
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-17/media/branch/master/" , littleLFS ))
125
+ resp = session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
126
+ assert .Equal (t , littleSize , resp .Length )
127
+
128
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-17/media/branch/master/" , bigLFS ))
129
+ resp = session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
130
+ assert .Equal (t , bigSize , resp .Length )
131
+ })
132
+
84
133
})
85
134
t .Run ("SSH" , func (t * testing.T ) {
86
135
sshContext := baseAPITestContext
@@ -97,6 +146,7 @@ func testGit(t *testing.T, u *url.URL) {
97
146
dstPath , err := ioutil .TempDir ("" , sshContext .Reponame )
98
147
assert .NoError (t , err )
99
148
defer os .RemoveAll (dstPath )
149
+ var little , big , littleLFS , bigLFS string
100
150
101
151
t .Run ("Standard" , func (t * testing.T ) {
102
152
t .Run ("CreateRepo" , doAPICreateRepository (sshContext , false ))
@@ -107,10 +157,10 @@ func testGit(t *testing.T, u *url.URL) {
107
157
//time.Sleep(5 * time.Minute)
108
158
t .Run ("PushCommit" , func (t * testing.T ) {
109
159
t .Run ("Little" , func (t * testing.T ) {
110
- commitAndPush (t , littleSize , dstPath )
160
+ little = commitAndPush (t , littleSize , dstPath )
111
161
})
112
162
t .Run ("Big" , func (t * testing.T ) {
113
- commitAndPush (t , bigSize , dstPath )
163
+ big = commitAndPush (t , bigSize , dstPath )
114
164
})
115
165
})
116
166
})
@@ -125,16 +175,59 @@ func testGit(t *testing.T, u *url.URL) {
125
175
assert .NoError (t , err )
126
176
127
177
t .Run ("Little" , func (t * testing.T ) {
128
- commitAndPush (t , littleSize , dstPath )
178
+ littleLFS = commitAndPush (t , littleSize , dstPath )
129
179
})
130
180
t .Run ("Big" , func (t * testing.T ) {
131
- commitAndPush (t , bigSize , dstPath )
181
+ bigLFS = commitAndPush (t , bigSize , dstPath )
132
182
})
133
183
})
134
184
t .Run ("Locks" , func (t * testing.T ) {
135
185
lockTest (t , u .String (), dstPath )
136
186
})
137
187
})
188
+ t .Run ("Raw" , func (t * testing.T ) {
189
+ session := loginUser (t , "user2" )
190
+
191
+ // Request raw paths
192
+ req := NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-18/raw/branch/master/" , little ))
193
+ resp := session .MakeRequest (t , req , http .StatusOK )
194
+ assert .Equal (t , littleSize , resp .Body .Len ())
195
+
196
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-18/raw/branch/master/" , big ))
197
+ resp = session .MakeRequest (t , req , http .StatusOK )
198
+ assert .Equal (t , bigSize , resp .Body .Len ())
199
+
200
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-18/raw/branch/master/" , littleLFS ))
201
+ resp = session .MakeRequest (t , req , http .StatusOK )
202
+ assert .NotEqual (t , littleSize , resp .Body .Len ())
203
+ assert .Contains (t , resp .Body .String (), models .LFSMetaFileIdentifier )
204
+
205
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-18/raw/branch/master/" , bigLFS ))
206
+ resp = session .MakeRequest (t , req , http .StatusOK )
207
+ assert .NotEqual (t , bigSize , resp .Body .Len ())
208
+ assert .Contains (t , resp .Body .String (), models .LFSMetaFileIdentifier )
209
+
210
+ })
211
+ t .Run ("Media" , func (t * testing.T ) {
212
+ session := loginUser (t , "user2" )
213
+
214
+ // Request media paths
215
+ req := NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-18/media/branch/master/" , little ))
216
+ resp := session .MakeRequest (t , req , http .StatusOK )
217
+ assert .Equal (t , littleSize , resp .Body .Len ())
218
+
219
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-18/media/branch/master/" , big ))
220
+ resp = session .MakeRequest (t , req , http .StatusOK )
221
+ assert .Equal (t , bigSize , resp .Body .Len ())
222
+
223
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-18/media/branch/master/" , littleLFS ))
224
+ resp = session .MakeRequest (t , req , http .StatusOK )
225
+ assert .Equal (t , littleSize , resp .Body .Len ())
226
+
227
+ req = NewRequest (t , "GET" , path .Join ("/user2/repo-tmp-18/media/branch/master/" , bigLFS ))
228
+ resp = session .MakeRequest (t , req , http .StatusOK )
229
+ assert .Equal (t , bigSize , resp .Body .Len ())
230
+ })
138
231
139
232
})
140
233
@@ -162,34 +255,35 @@ func lockTest(t *testing.T, remote, repoPath string) {
162
255
assert .NoError (t , err )
163
256
}
164
257
165
- func commitAndPush (t * testing.T , size int , repoPath string ) {
166
- err := generateCommitWithNewData (
size ,
repoPath ,
"[email protected] " ,
"User Two" )
258
+ func commitAndPush (t * testing.T , size int , repoPath string ) string {
259
+ name , err := generateCommitWithNewData (
size ,
repoPath ,
"[email protected] " ,
"User Two" )
167
260
assert .NoError (t , err )
168
261
_ , err = git .NewCommand ("push" ).RunInDir (repoPath ) //Push
169
262
assert .NoError (t , err )
263
+ return name
170
264
}
171
265
172
- func generateCommitWithNewData (size int , repoPath , email , fullName string ) error {
266
+ func generateCommitWithNewData (size int , repoPath , email , fullName string ) ( string , error ) {
173
267
//Generate random file
174
268
data := make ([]byte , size )
175
269
_ , err := rand .Read (data )
176
270
if err != nil {
177
- return err
271
+ return "" , err
178
272
}
179
273
tmpFile , err := ioutil .TempFile (repoPath , "data-file-" )
180
274
if err != nil {
181
- return err
275
+ return "" , err
182
276
}
183
277
defer tmpFile .Close ()
184
278
_ , err = tmpFile .Write (data )
185
279
if err != nil {
186
- return err
280
+ return "" , err
187
281
}
188
282
189
283
//Commit
190
284
err = git .AddChanges (repoPath , false , filepath .Base (tmpFile .Name ()))
191
285
if err != nil {
192
- return err
286
+ return "" , err
193
287
}
194
288
err = git .CommitChanges (repoPath , git.CommitChangesOptions {
195
289
Committer : & git.Signature {
@@ -204,5 +298,5 @@ func generateCommitWithNewData(size int, repoPath, email, fullName string) error
204
298
},
205
299
Message : fmt .Sprintf ("Testing commit @ %v" , time .Now ()),
206
300
})
207
- return err
301
+ return filepath . Base ( tmpFile . Name ()), err
208
302
}
0 commit comments