From 4a5d9d4b78c6084a38ce278d16f9ba6d11d912f8 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 15 Nov 2024 14:02:16 +0100 Subject: [PATCH] chore: fix e2e - Regression from #5948 - Use proper permission. - Remove debug statement --- tests/e2e/utils_e2e_test.go | 10 ++++++++++ tests/integration/git_helper_for_declarative_test.go | 4 ++-- tests/test_utils.go | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/e2e/utils_e2e_test.go b/tests/e2e/utils_e2e_test.go index cfd3ff9e3b..bf1a8a418c 100644 --- a/tests/e2e/utils_e2e_test.go +++ b/tests/e2e/utils_e2e_test.go @@ -8,6 +8,8 @@ import ( "net" "net/http" "net/url" + "os" + "regexp" "testing" "time" @@ -17,6 +19,8 @@ import ( "github.com/stretchr/testify/require" ) +var rootPathRe = regexp.MustCompile("\\[repository\\]\nROOT\\s=\\s.*") + func onForgejoRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) { if len(prepare) == 0 || prepare[0] { defer tests.PrepareTestEnv(t, 1)() @@ -37,7 +41,13 @@ func onForgejoRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare . require.NoError(t, err) u.Host = listener.Addr().String() + // Override repository root in config. + conf, err := os.ReadFile(setting.CustomConf) + require.NoError(t, err) + require.NoError(t, os.WriteFile(setting.CustomConf, rootPathRe.ReplaceAll(conf, []byte("[repository]\nROOT = "+setting.RepoRootPath)), 0o644)) + defer func() { + require.NoError(t, os.WriteFile(setting.CustomConf, conf, 0o644)) ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) s.Shutdown(ctx) cancel() diff --git a/tests/integration/git_helper_for_declarative_test.go b/tests/integration/git_helper_for_declarative_test.go index 11c72ce7f3..83d8177460 100644 --- a/tests/integration/git_helper_for_declarative_test.go +++ b/tests/integration/git_helper_for_declarative_test.go @@ -83,10 +83,10 @@ func onGiteaRun[T testing.TB](t T, callback func(T, *url.URL)) { // Override repository root in config. conf, err := os.ReadFile(setting.CustomConf) require.NoError(t, err) - require.NoError(t, os.WriteFile(setting.CustomConf, rootPathRe.ReplaceAll(conf, []byte("[repository]\nROOT = "+setting.RepoRootPath)), os.ModePerm)) + require.NoError(t, os.WriteFile(setting.CustomConf, rootPathRe.ReplaceAll(conf, []byte("[repository]\nROOT = "+setting.RepoRootPath)), 0o600)) defer func() { - require.NoError(t, os.WriteFile(setting.CustomConf, conf, os.ModePerm)) + require.NoError(t, os.WriteFile(setting.CustomConf, conf, 0o600)) ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) s.Shutdown(ctx) cancel() diff --git a/tests/test_utils.go b/tests/test_utils.go index 55cbc8eb10..b3c03a30a1 100644 --- a/tests/test_utils.go +++ b/tests/test_utils.go @@ -201,7 +201,6 @@ func InitTest(requireGitea bool) { if err != nil { log.Fatal("os.ReadDir: %v", err) } - fmt.Println(ownerDirs) for _, ownerDir := range ownerDirs { if !ownerDir.Type().IsDir() {