Finally remove utils.Cfg (#8113)
* finally remove utils.Cfg * fix compile error * another test compilation fix
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
dce0616305
Коммит
4e6cc846a6
@@ -61,15 +61,11 @@ func TestUpdateConfig(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
prev := *th.App.Config().ServiceSettings.SiteURL
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.SiteURL = prev
|
||||
})
|
||||
|
||||
listener := th.App.AddConfigListener(func(old, current *model.Config) {
|
||||
th.App.AddConfigListener(func(old, current *model.Config) {
|
||||
assert.Equal(t, prev, *old.ServiceSettings.SiteURL)
|
||||
assert.Equal(t, "foo", *current.ServiceSettings.SiteURL)
|
||||
})
|
||||
defer th.App.RemoveConfigListener(listener)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.SiteURL = "foo"
|
||||
|
||||
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -29,8 +30,9 @@ type TestHelper struct {
|
||||
BasicChannel *model.Channel
|
||||
BasicPost *model.Post
|
||||
|
||||
tempWorkspace string
|
||||
pluginHooks map[string]plugin.Hooks
|
||||
tempConfigPath string
|
||||
tempWorkspace string
|
||||
pluginHooks map[string]plugin.Hooks
|
||||
}
|
||||
|
||||
type persistentTestStore struct {
|
||||
@@ -57,7 +59,22 @@ func StopTestStore() {
|
||||
}
|
||||
|
||||
func setupTestHelper(enterprise bool) *TestHelper {
|
||||
options := []Option{DisableConfigWatch}
|
||||
permConfig, err := os.Open(utils.FindConfigFile("config.json"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer permConfig.Close()
|
||||
tempConfig, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = io.Copy(tempConfig, permConfig)
|
||||
tempConfig.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
options := []Option{ConfigFile(tempConfig.Name()), DisableConfigWatch}
|
||||
if testStore != nil {
|
||||
options = append(options, StoreOverride(testStore))
|
||||
}
|
||||
@@ -68,8 +85,9 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
||||
}
|
||||
|
||||
th := &TestHelper{
|
||||
App: a,
|
||||
pluginHooks: make(map[string]plugin.Hooks),
|
||||
App: a,
|
||||
pluginHooks: make(map[string]plugin.Hooks),
|
||||
tempConfigPath: tempConfig.Name(),
|
||||
}
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
||||
@@ -232,6 +250,7 @@ func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
|
||||
func (me *TestHelper) TearDown() {
|
||||
me.App.Shutdown()
|
||||
os.Remove(me.tempConfigPath)
|
||||
if err := recover(); err != nil {
|
||||
StopTestStore()
|
||||
panic(err)
|
||||
|
||||
@@ -27,7 +27,6 @@ func (a *App) UpdateConfig(f func(*model.Config)) {
|
||||
updated := old.Clone()
|
||||
f(updated)
|
||||
a.config.Store(updated)
|
||||
utils.Cfg = updated
|
||||
a.InvokeConfigListeners(old, updated)
|
||||
}
|
||||
|
||||
@@ -48,7 +47,6 @@ func (a *App) LoadConfig(configFile string) *model.AppError {
|
||||
utils.ConfigureLog(&cfg.LogSettings)
|
||||
|
||||
a.config.Store(cfg)
|
||||
utils.Cfg = cfg
|
||||
|
||||
utils.SetSiteURL(*cfg.ServiceSettings.SiteURL)
|
||||
|
||||
|
||||
@@ -155,9 +155,7 @@ func TestDiagnostics(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("SendDailyDiagnosticsDisabled", func(t *testing.T) {
|
||||
oldSetting := *th.App.Config().LogSettings.EnableDiagnostics
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.LogSettings.EnableDiagnostics = false })
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.LogSettings.EnableDiagnostics = oldSetting })
|
||||
|
||||
th.App.SendDailyDiagnostics()
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ func (a *App) LoadLicense() {
|
||||
|
||||
if len(licenseId) != 26 {
|
||||
// Lets attempt to load the file from disk since it was missing from the DB
|
||||
license, licenseBytes := utils.GetAndValidateLicenseFileFromDisk()
|
||||
license, licenseBytes := utils.GetAndValidateLicenseFileFromDisk(*a.Config().ServiceSettings.LicenseFileLocation)
|
||||
|
||||
if license != nil {
|
||||
if _, err := a.SaveLicense(licenseBytes); err != nil {
|
||||
|
||||
@@ -49,10 +49,6 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
th := Setup()
|
||||
defer th.TearDown()
|
||||
|
||||
oldSetting := th.App.Config().ServiceSettings.EnableOAuthServiceProvider
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.ServiceSettings.EnableOAuthServiceProvider = oldSetting
|
||||
})
|
||||
th.App.Config().ServiceSettings.EnableOAuthServiceProvider = true
|
||||
|
||||
a1 := &model.OAuthApp{}
|
||||
|
||||
@@ -88,10 +88,6 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
|
||||
th.App.PermanentDeleteUser(user)
|
||||
|
||||
userCreation := th.App.Config().TeamSettings.EnableUserCreation
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.TeamSettings.EnableUserCreation = userCreation
|
||||
})
|
||||
th.App.Config().TeamSettings.EnableUserCreation = false
|
||||
|
||||
_, err = th.App.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
|
||||
@@ -17,13 +17,6 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
|
||||
enablePostUsernameOverride := th.App.Config().ServiceSettings.EnablePostUsernameOverride
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = enablePostUsernameOverride })
|
||||
enablePostIconOverride := th.App.Config().ServiceSettings.EnablePostIconOverride
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = enablePostIconOverride })
|
||||
|
||||
type TestCase struct {
|
||||
EnableIncomingHooks bool
|
||||
EnablePostUsernameOverride bool
|
||||
@@ -155,13 +148,6 @@ func TestUpdateIncomingWebhook(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
|
||||
enablePostUsernameOverride := th.App.Config().ServiceSettings.EnablePostUsernameOverride
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = enablePostUsernameOverride })
|
||||
enablePostIconOverride := th.App.Config().ServiceSettings.EnablePostIconOverride
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = enablePostIconOverride })
|
||||
|
||||
type TestCase struct {
|
||||
EnableIncomingHooks bool
|
||||
EnablePostUsernameOverride bool
|
||||
@@ -300,8 +286,6 @@ func TestCreateWebhookPost(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||
|
||||
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
||||
|
||||
Ссылка в новой задаче
Block a user