From 377a0a20f01a62f15a1504a3bba6cf6cc0c98bea Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 4 May 2023 11:55:35 +0800 Subject: Merge setting.InitXXX into one function with options (#24389) This PR will merge 3 Init functions on setting packages as 1 and introduce an options struct. --- routers/api/v1/repo/main_test.go | 7 ++++--- routers/install/setting.go | 8 ++++---- routers/web/user/setting/account_test.go | 27 +++++++++++++++------------ 3 files changed, 23 insertions(+), 19 deletions(-) (limited to 'routers') diff --git a/routers/api/v1/repo/main_test.go b/routers/api/v1/repo/main_test.go index c7466c493f..bc048505f4 100644 --- a/routers/api/v1/repo/main_test.go +++ b/routers/api/v1/repo/main_test.go @@ -13,10 +13,11 @@ import ( ) func TestMain(m *testing.M) { - setting.InitProviderAndLoadCommonSettingsForTest() - setting.LoadQueueSettings() unittest.MainTest(m, &unittest.TestOptions{ GiteaRootPath: filepath.Join("..", "..", "..", ".."), - SetUp: webhook_service.Init, + SetUp: func() error { + setting.LoadQueueSettings() + return webhook_service.Init() + }, }) } diff --git a/routers/install/setting.go b/routers/install/setting.go index dadefa26a2..c14843d8ee 100644 --- a/routers/install/setting.go +++ b/routers/install/setting.go @@ -15,8 +15,9 @@ import ( // PreloadSettings preloads the configuration to check if we need to run install func PreloadSettings(ctx context.Context) bool { - setting.InitProviderAllowEmpty() - setting.LoadCommonSettings() + setting.Init(&setting.Options{ + AllowEmpty: true, + }) if !setting.InstallLock { log.Info("AppPath: %s", setting.AppPath) log.Info("AppWorkPath: %s", setting.AppWorkPath) @@ -38,8 +39,7 @@ func PreloadSettings(ctx context.Context) bool { // reloadSettings reloads the existing settings and starts up the database func reloadSettings(ctx context.Context) { - setting.InitProviderFromExistingFile() - setting.LoadCommonSettings() + setting.Init(&setting.Options{}) setting.LoadDBSetting() if setting.InstallLock { if err := common.InitDBEngine(ctx); err == nil { diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go index 5fce41f065..569d597722 100644 --- a/routers/web/user/setting/account_test.go +++ b/routers/web/user/setting/account_test.go @@ -80,19 +80,22 @@ func TestChangePassword(t *testing.T) { PasswordComplexity: pcLU, }, } { - unittest.PrepareTestEnv(t) - ctx := test.MockContext(t, "user/settings/security") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + t.Run(req.OldPassword+"__"+req.NewPassword, func(t *testing.T) { + unittest.PrepareTestEnv(t) + setting.PasswordComplexity = req.PasswordComplexity + ctx := test.MockContext(t, "user/settings/security") + test.LoadUser(t, ctx, 2) + test.LoadRepo(t, ctx, 1) - web.SetForm(ctx, &forms.ChangePasswordForm{ - OldPassword: req.OldPassword, - Password: req.NewPassword, - Retype: req.Retype, - }) - AccountPost(ctx) + web.SetForm(ctx, &forms.ChangePasswordForm{ + OldPassword: req.OldPassword, + Password: req.NewPassword, + Retype: req.Retype, + }) + AccountPost(ctx) - assert.Contains(t, ctx.Flash.ErrorMsg, req.Message) - assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) + assert.Contains(t, ctx.Flash.ErrorMsg, req.Message) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) + }) } } -- cgit v1.2.3