@@ -192,32 +192,7 @@ func PrepareAttachmentsStorage(t testing.TB) {
192192 }))
193193}
194194
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 ) {
221196 assert .NoError (t , util .RemoveAll (setting .RepoRootPath ))
222197 assert .NoError (t , unittest .CopyDir (path .Join (filepath .Dir (setting .AppPath ), "tests/gitea-repositories-meta" ), setting .RepoRootPath ))
223198
@@ -241,12 +216,25 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
241216 _ = os .MkdirAll (filepath .Join (setting .RepoRootPath , ownerDir .Name (), repoDir .Name (), "refs" , "pull" ), 0o755 )
242217 }
243218 }
219+ }
244220
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+ }
247234
235+ func PrepareLFSStorage (t testing.TB ) {
248236 // 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)
250238 lfsFixtures , err := storage .NewStorage (setting .LocalStorageType , & setting.Storage {
251239 Path : filepath .Join (filepath .Dir (setting .AppPath ), "tests/gitea-lfs-meta" ),
252240 })
@@ -256,7 +244,9 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
256244 _ , err := storage .Copy (storage .LFS , path , lfsFixtures , path )
257245 return err
258246 }))
247+ }
259248
249+ func PrepareCleanPackageData (t testing.TB ) {
260250 // clear all package data
261251 assert .NoError (t , db .TruncateBeans (db .DefaultContext ,
262252 & packages_model.Package {},
@@ -268,17 +258,25 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
268258 & packages_model.PackageCleanupRule {},
269259 ))
270260 assert .NoError (t , storage .Clean (storage .Packages ))
261+ }
271262
263+ func PrepareTestEnv (t testing.TB , skip ... int ) func () {
264+ t .Helper ()
265+ deferFn := PrintCurrentTest (t , util .DefArgZero (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 )
272274 return deferFn
273275}
274276
275277func PrintCurrentTest (t testing.TB , skip ... int ) func () {
276278 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 .DefArgZero (skip )+ 1 )
282280}
283281
284282// Printf takes a format and args and prints the string to os.Stdout
0 commit comments