@@ -192,32 +192,7 @@ func PrepareAttachmentsStorage(t testing.TB) {
192
192
}))
193
193
}
194
194
195
- func PrepareArtifactsStorage (t testing.TB ) {
196
- // prepare actions artifacts directory and files
197
- assert .NoError (t , storage .Clean (storage .ActionsArtifacts ))
198
-
199
- s , err := storage .NewStorage (setting .LocalStorageType , & setting.Storage {
200
- Path : filepath .Join (filepath .Dir (setting .AppPath ), "tests" , "testdata" , "data" , "artifacts" ),
201
- })
202
- assert .NoError (t , err )
203
- assert .NoError (t , s .IterateObjects ("" , func (p string , obj storage.Object ) error {
204
- _ , err = storage .Copy (storage .ActionsArtifacts , p , s , p )
205
- return err
206
- }))
207
- }
208
-
209
- func PrepareTestEnv (t testing.TB , skip ... int ) func () {
210
- t .Helper ()
211
- ourSkip := 1
212
- if len (skip ) > 0 {
213
- ourSkip += skip [0 ]
214
- }
215
- deferFn := PrintCurrentTest (t , ourSkip )
216
-
217
- // load database fixtures
218
- assert .NoError (t , unittest .LoadFixtures ())
219
-
220
- // load git repo fixtures
195
+ func PrepareGitRepoDirectory (t testing.TB ) {
221
196
assert .NoError (t , util .RemoveAll (setting .RepoRootPath ))
222
197
assert .NoError (t , unittest .CopyDir (path .Join (filepath .Dir (setting .AppPath ), "tests/gitea-repositories-meta" ), setting .RepoRootPath ))
223
198
@@ -241,12 +216,25 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
241
216
_ = os .MkdirAll (filepath .Join (setting .RepoRootPath , ownerDir .Name (), repoDir .Name (), "refs" , "pull" ), 0o755 )
242
217
}
243
218
}
219
+ }
244
220
245
- // Initialize actions artifact data
246
- PrepareArtifactsStorage (t )
221
+ func PrepareArtifactsStorage (t testing.TB ) {
222
+ // prepare actions artifacts directory and files
223
+ assert .NoError (t , storage .Clean (storage .ActionsArtifacts ))
224
+
225
+ s , err := storage .NewStorage (setting .LocalStorageType , & setting.Storage {
226
+ Path : filepath .Join (filepath .Dir (setting .AppPath ), "tests" , "testdata" , "data" , "artifacts" ),
227
+ })
228
+ assert .NoError (t , err )
229
+ assert .NoError (t , s .IterateObjects ("" , func (p string , obj storage.Object ) error {
230
+ _ , err = storage .Copy (storage .ActionsArtifacts , p , s , p )
231
+ return err
232
+ }))
233
+ }
247
234
235
+ func PrepareLFSStorage (t testing.TB ) {
248
236
// load LFS object fixtures
249
- // (LFS storage can be on any of several backends, including remote servers, so we init it with the storage API)
237
+ // (LFS storage can be on any of several backends, including remote servers, so init it with the storage API)
250
238
lfsFixtures , err := storage .NewStorage (setting .LocalStorageType , & setting.Storage {
251
239
Path : filepath .Join (filepath .Dir (setting .AppPath ), "tests/gitea-lfs-meta" ),
252
240
})
@@ -256,7 +244,9 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
256
244
_ , err := storage .Copy (storage .LFS , path , lfsFixtures , path )
257
245
return err
258
246
}))
247
+ }
259
248
249
+ func PrepareCleanPackageData (t testing.TB ) {
260
250
// clear all package data
261
251
assert .NoError (t , db .TruncateBeans (db .DefaultContext ,
262
252
& packages_model.Package {},
@@ -268,17 +258,25 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
268
258
& packages_model.PackageCleanupRule {},
269
259
))
270
260
assert .NoError (t , storage .Clean (storage .Packages ))
261
+ }
271
262
263
+ func PrepareTestEnv (t testing.TB , skip ... int ) func () {
264
+ t .Helper ()
265
+ deferFn := PrintCurrentTest (t , util .OptionalArg (skip )+ 1 )
266
+
267
+ // load database fixtures
268
+ assert .NoError (t , unittest .LoadFixtures ())
269
+
270
+ // do not add more Prepare* functions here, only call necessary ones in the related test functions
271
+ PrepareGitRepoDirectory (t )
272
+ PrepareLFSStorage (t )
273
+ PrepareCleanPackageData (t )
272
274
return deferFn
273
275
}
274
276
275
277
func PrintCurrentTest (t testing.TB , skip ... int ) func () {
276
278
t .Helper ()
277
- actualSkip := 1
278
- if len (skip ) > 0 {
279
- actualSkip = skip [0 ] + 1
280
- }
281
- return testlogger .PrintCurrentTest (t , actualSkip )
279
+ return testlogger .PrintCurrentTest (t , util .OptionalArg (skip )+ 1 )
282
280
}
283
281
284
282
// Printf takes a format and args and prints the string to os.Stdout
0 commit comments