summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2018-01-17 12:38:37 -0600
committerHarrison Healey <harrisonmhealey@gmail.com>2018-01-17 13:38:37 -0500
commit4e6cc846a618ecef5c101727bbd03f6674044ab7 (patch)
tree1fc093b4b338acf34180c93f30a32de50e17d089 /app
parentdce061630530c467966378ae3c5adbcf4a09e34f (diff)
downloadchat-4e6cc846a618ecef5c101727bbd03f6674044ab7.tar.gz
chat-4e6cc846a618ecef5c101727bbd03f6674044ab7.tar.bz2
chat-4e6cc846a618ecef5c101727bbd03f6674044ab7.zip
Finally remove utils.Cfg (#8113)
* finally remove utils.Cfg * fix compile error * another test compilation fix
Diffstat (limited to 'app')
-rw-r--r--app/app_test.go6
-rw-r--r--app/apptestlib.go29
-rw-r--r--app/config.go2
-rw-r--r--app/diagnostics_test.go2
-rw-r--r--app/license.go2
-rw-r--r--app/oauth_test.go4
-rw-r--r--app/user_test.go4
-rw-r--r--app/webhook_test.go16
8 files changed, 26 insertions, 39 deletions
diff --git a/app/app_test.go b/app/app_test.go
index b686381ea..25b19ead8 100644
--- a/app/app_test.go
+++ b/app/app_test.go
@@ -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"
diff --git a/app/apptestlib.go b/app/apptestlib.go
index 1ec45f0fa..09afc8f76 100644
--- a/app/apptestlib.go
+++ b/app/apptestlib.go
@@ -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)
diff --git a/app/config.go b/app/config.go
index 3039d4426..526d47a77 100644
--- a/app/config.go
+++ b/app/config.go
@@ -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)
diff --git a/app/diagnostics_test.go b/app/diagnostics_test.go
index 0869e4df4..869e5ddc6 100644
--- a/app/diagnostics_test.go
+++ b/app/diagnostics_test.go
@@ -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()
diff --git a/app/license.go b/app/license.go
index cacc71524..c7fd07197 100644
--- a/app/license.go
+++ b/app/license.go
@@ -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 {
diff --git a/app/oauth_test.go b/app/oauth_test.go
index b964b377d..60854a354 100644
--- a/app/oauth_test.go
+++ b/app/oauth_test.go
@@ -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{}
diff --git a/app/user_test.go b/app/user_test.go
index 3a924dfa7..38ff286b3 100644
--- a/app/user_test.go
+++ b/app/user_test.go
@@ -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)
diff --git a/app/webhook_test.go b/app/webhook_test.go
index 47303ee93..850e74efc 100644
--- a/app/webhook_test.go
+++ b/app/webhook_test.go
@@ -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})