mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-13 02:35:27 +00:00
clean up
This commit is contained in:
@@ -192,13 +192,13 @@ func RunGitTests(m interface{ Run() int }) {
|
||||
func runGitTests(m interface{ Run() int }) int {
|
||||
gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
|
||||
if err != nil {
|
||||
testlogger.Panicf("unable to create temp dir: %s", err.Error())
|
||||
return testlogger.MainErrorf("unable to create temp dir: %v", err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
setting.Git.HomePath = gitHomePath
|
||||
if err = InitFull(); err != nil {
|
||||
testlogger.Panicf("failed to call Init: %s", err.Error())
|
||||
return testlogger.MainErrorf("failed to call Init: %s", err)
|
||||
}
|
||||
return m.Run()
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func testMain(m *testing.M) int {
|
||||
// "setting.Git.HomePath" is initialized in "git" package but really used in "gitcmd" package
|
||||
gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
|
||||
if err != nil {
|
||||
testlogger.Panicf("failed to create temp dir: %v", err)
|
||||
return testlogger.MainErrorf("failed to create temp dir: %v", err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
|
||||
@@ -101,6 +101,10 @@ func SetupGiteaTestEnv() {
|
||||
cleanUpEnv()
|
||||
initWorkPathAndConfig()
|
||||
|
||||
if RepoRootPath == "" || AppDataPath == "" {
|
||||
panic("SetupGiteaTestEnv failed, paths are not initialized")
|
||||
}
|
||||
|
||||
// TODO: some git repo hooks (test fixtures) still use these env variables, need to be refactored in the future
|
||||
_ = os.Setenv("GITEA_ROOT", giteaRoot)
|
||||
_ = os.Setenv("GITEA_CONF", giteaConf) // test fixture git hooks use "$GITEA_ROOT/$GITEA_CONF" in their scripts
|
||||
|
||||
@@ -173,7 +173,8 @@ func Init() {
|
||||
log.RegisterEventWriter("test", newTestLoggerWriter)
|
||||
}
|
||||
|
||||
func Panicf(format string, args ...any) {
|
||||
// don't call os.Exit, otherwise the "defer" functions won't be executed
|
||||
panic(fmt.Sprintf(format, args...))
|
||||
// MainErrorf is used to report an error from TestMain and return a non-zero value to indicate the failure
|
||||
func MainErrorf(msg string, a ...any) int {
|
||||
_, _ = fmt.Fprintf(os.Stderr, msg+"\n", a...)
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user