mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-13 02:35:27 +00:00
fix
This commit is contained in:
2
Makefile
2
Makefile
@@ -411,7 +411,7 @@ coverage:
|
||||
.PHONY: unit-test-coverage
|
||||
unit-test-coverage:
|
||||
@echo "Running unit-test-coverage $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
|
||||
@$(GO) test $(GOTESTFLAGS) -timeout=20m -tags='$(TEST_TAGS)' -v -cover -coverprofile coverage.out $(GO_TEST_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
||||
@$(GO) test $(GOTESTFLAGS) -timeout=20m -tags='$(TEST_TAGS)' -cover -coverprofile coverage.out $(GO_TEST_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
||||
|
||||
.PHONY: tidy
|
||||
tidy: ## run go mod tidy
|
||||
|
||||
@@ -22,8 +22,6 @@ import (
|
||||
func TestMigratePackages(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
t.Log("DebugLogs", setting.DebugGetLogs())
|
||||
|
||||
creator := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
|
||||
content := "package main\n\nfunc main() {\nfmt.Println(\"hi\")\n}\n"
|
||||
|
||||
@@ -47,24 +47,13 @@ func mainTest(m *testing.M, testOptsArg ...*TestOptions) int {
|
||||
|
||||
testOpts := util.OptionalArg(testOptsArg, &TestOptions{})
|
||||
|
||||
appDataPath, appDataCleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("unit-test-data-")
|
||||
tempWorkPath, tempCleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("unit-test-dir-")
|
||||
if err != nil {
|
||||
return reportError("Failed to create temp dir for app data path: %v", err)
|
||||
return reportError("Failed to create temp dir for unit test: %v", err)
|
||||
}
|
||||
defer tempCleanup()
|
||||
|
||||
// FIXME: debug
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Prepare APP_DATA_PATH for SetupGiteaTestEnv: %s\n", appDataPath)
|
||||
setting.DebugAppendLog("Prepare APP_DATA_PATH for SetupGiteaTestEnv: %s", appDataPath)
|
||||
defer func() {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Remove APP_DATA_PATH for SetupGiteaTestEnv: %s\n", appDataPath)
|
||||
setting.DebugAppendLog("Remove APP_DATA_PATH for SetupGiteaTestEnv: %s", appDataPath)
|
||||
appDataCleanup()
|
||||
}()
|
||||
|
||||
_ = os.Setenv("GITEA_TEST_CONF_CONTENT", `
|
||||
[server]
|
||||
APP_DATA_PATH = `+appDataPath+`
|
||||
`)
|
||||
defer setting.MockBuiltinPaths(tempWorkPath, "", "")()
|
||||
setting.SetupGiteaTestEnv()
|
||||
if setting.RepoRootPath == "" || setting.AppDataPath == "" {
|
||||
return reportError("SetupGiteaTestEnv failed, paths are not initialized")
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -278,11 +278,6 @@ func loadServerFrom(rootCfg ConfigProvider) {
|
||||
StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(StaticRootPath)
|
||||
StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour)
|
||||
AppDataPath = sec.Key("APP_DATA_PATH").MustString(filepath.Join(AppWorkPath, "data"))
|
||||
|
||||
// FIXME: debug
|
||||
bufCustomConf, _ := os.ReadFile(CustomConf)
|
||||
log.Error("Set AppDataPath=%s (CustomConf=%s)\n%s\n%s\n", AppDataPath, CustomConf, string(bufCustomConf), log.Stack(2))
|
||||
DebugAppendLog("Set AppDataPath=%s (CustomConf=%s)\n%s\n%s\n", AppDataPath, CustomConf, string(bufCustomConf), log.Stack(2))
|
||||
if !filepath.IsAbs(AppDataPath) {
|
||||
AppDataPath = filepath.ToSlash(filepath.Join(AppWorkPath, AppDataPath))
|
||||
}
|
||||
|
||||
@@ -21,19 +21,6 @@ func GetGiteaTestSourceRoot() string {
|
||||
return *giteaTestSourceRoot
|
||||
}
|
||||
|
||||
func DebugAppendLog(msg string, a ...any) {
|
||||
f, _ := os.OpenFile("/tmp/debug.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
if f != nil {
|
||||
defer f.Close()
|
||||
fmt.Fprintf(f, msg+"\n", a...)
|
||||
}
|
||||
}
|
||||
|
||||
func DebugGetLogs() string {
|
||||
buf, _ := os.ReadFile("/tmp/debug.log")
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
func SetupGiteaTestEnv() {
|
||||
if giteaTestSourceRoot != nil {
|
||||
return // already initialized
|
||||
@@ -75,14 +62,11 @@ func SetupGiteaTestEnv() {
|
||||
giteaConf := os.Getenv("GITEA_TEST_CONF")
|
||||
if giteaConf == "" {
|
||||
// if no GITEA_TEST_CONF, then it is in unit test, use a temp (non-existing / empty) config file
|
||||
// do not really use such config file, the test can run concurrently, using the same config file will cause data-race between tests
|
||||
giteaConf = "custom/conf/app-test-tmp.ini"
|
||||
customConfBuiltin = filepath.Join(AppWorkPath, giteaConf)
|
||||
CustomConf = customConfBuiltin
|
||||
_ = os.WriteFile(CustomConf, []byte(os.Getenv("GITEA_TEST_CONF_CONTENT")), 0o644)
|
||||
|
||||
// FIXME: debug
|
||||
log.Error("SetupGiteaTestEnv CustomConf=%s\n%s\n%s\n", CustomConf, os.Getenv("GITEA_TEST_CONF_CONTENT"), log.Stack(2))
|
||||
DebugAppendLog("SetupGiteaTestEnv CustomConf=%s\n%s\n%s\n", CustomConf, os.Getenv("GITEA_TEST_CONF_CONTENT"), log.Stack(2))
|
||||
_ = os.Remove(CustomConf)
|
||||
} else {
|
||||
// CustomConf must be absolute path to make tests pass,
|
||||
CustomConf = filepath.Join(AppWorkPath, giteaConf)
|
||||
|
||||
Reference in New Issue
Block a user