@@ -8,15 +8,13 @@ import (
88 "context"
99 "fmt"
1010 "os"
11- "path"
1211 "path/filepath"
1312 "runtime"
1413 "testing"
1514
1615 "code.gitea.io/gitea/models/unittest"
1716 "code.gitea.io/gitea/modules/base"
1817 "code.gitea.io/gitea/modules/git"
19- "code.gitea.io/gitea/modules/log"
2018 "code.gitea.io/gitea/modules/setting"
2119 "code.gitea.io/gitea/modules/testlogger"
2220
@@ -35,27 +33,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
3533 ourSkip := 2
3634 ourSkip += skip
3735 deferFn := testlogger .PrintCurrentTest (t , ourSkip )
38- assert .NoError (t , os .RemoveAll (setting .RepoRootPath ))
39- assert .NoError (t , unittest .CopyDir (path .Join (filepath .Dir (setting .AppPath ), "tests/gitea-repositories-meta" ), setting .RepoRootPath ))
40- ownerDirs , err := os .ReadDir (setting .RepoRootPath )
41- if err != nil {
42- assert .NoError (t , err , "unable to read the new repo root: %v\n " , err )
43- }
44- for _ , ownerDir := range ownerDirs {
45- if ! ownerDir .Type ().IsDir () {
46- continue
47- }
48- repoDirs , err := os .ReadDir (filepath .Join (setting .RepoRootPath , ownerDir .Name ()))
49- if err != nil {
50- assert .NoError (t , err , "unable to read the new repo root: %v\n " , err )
51- }
52- for _ , repoDir := range repoDirs {
53- _ = os .MkdirAll (filepath .Join (setting .RepoRootPath , ownerDir .Name (), repoDir .Name (), "objects" , "pack" ), 0o755 )
54- _ = os .MkdirAll (filepath .Join (setting .RepoRootPath , ownerDir .Name (), repoDir .Name (), "objects" , "info" ), 0o755 )
55- _ = os .MkdirAll (filepath .Join (setting .RepoRootPath , ownerDir .Name (), repoDir .Name (), "refs" , "heads" ), 0o755 )
56- _ = os .MkdirAll (filepath .Join (setting .RepoRootPath , ownerDir .Name (), repoDir .Name (), "refs" , "tag" ), 0o755 )
57- }
58- }
36+ assert .NoError (t , unittest .SyncDirs (filepath .Join (filepath .Dir (setting .AppPath ), "tests/gitea-repositories-meta" ), setting .RepoRootPath ))
5937
6038 if err := deleteDB (); err != nil {
6139 t .Errorf ("unable to reset database: %v" , err )
@@ -112,48 +90,44 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
11290}
11391
11492func MainTest (m * testing.M ) {
115- log . RegisterEventWriter ( "test" , testlogger .NewTestLoggerWriter )
93+ testlogger .Init ( )
11694
11795 giteaRoot := base .SetupGiteaRoot ()
11896 if giteaRoot == "" {
119- fmt .Println ("Environment variable $GITEA_ROOT not set" )
120- os .Exit (1 )
97+ testlogger .Fatalf ("Environment variable $GITEA_ROOT not set\n " )
12198 }
12299 giteaBinary := "gitea"
123100 if runtime .GOOS == "windows" {
124101 giteaBinary += ".exe"
125102 }
126- setting .AppPath = path .Join (giteaRoot , giteaBinary )
103+ setting .AppPath = filepath .Join (giteaRoot , giteaBinary )
127104 if _ , err := os .Stat (setting .AppPath ); err != nil {
128- fmt .Printf ("Could not find gitea binary at %s\n " , setting .AppPath )
129- os .Exit (1 )
105+ testlogger .Fatalf ("Could not find gitea binary at %s\n " , setting .AppPath )
130106 }
131107
132108 giteaConf := os .Getenv ("GITEA_CONF" )
133109 if giteaConf == "" {
134- giteaConf = path .Join (filepath .Dir (setting .AppPath ), "tests/sqlite.ini" )
110+ giteaConf = filepath .Join (filepath .Dir (setting .AppPath ), "tests/sqlite.ini" )
135111 fmt .Printf ("Environment variable $GITEA_CONF not set - defaulting to %s\n " , giteaConf )
136112 }
137113
138- if ! path .IsAbs (giteaConf ) {
139- setting .CustomConf = path .Join (giteaRoot , giteaConf )
114+ if ! filepath .IsAbs (giteaConf ) {
115+ setting .CustomConf = filepath .Join (giteaRoot , giteaConf )
140116 } else {
141117 setting .CustomConf = giteaConf
142118 }
143119
144120 tmpDataPath , err := os .MkdirTemp ("" , "data" )
145121 if err != nil {
146- fmt .Printf ("Unable to create temporary data path %v\n " , err )
147- os .Exit (1 )
122+ testlogger .Fatalf ("Unable to create temporary data path %v\n " , err )
148123 }
149124
150125 setting .CustomPath = filepath .Join (setting .AppWorkPath , "custom" )
151126 setting .AppDataPath = tmpDataPath
152127
153128 unittest .InitSettings ()
154129 if err = git .InitFull (context .Background ()); err != nil {
155- fmt .Printf ("Unable to InitFull: %v\n " , err )
156- os .Exit (1 )
130+ testlogger .Fatalf ("Unable to InitFull: %v\n " , err )
157131 }
158132 setting .LoadDBSetting ()
159133 setting .InitLoggersForTest ()
0 commit comments