PLT-6076 Read config file info from enviroment vars (#5873)

* Adding viper libs for config file changes

* Removing the old fsnotify lib

* updating some missing libs

* PLT-6076 Read config file info from enviroment vars

* Changing unit test to use less important props
Этот коммит содержится в:
Corey Hulen
2017-03-29 18:13:32 -07:00
коммит произвёл Joram Wilander
родитель 6ac87d82e3
Коммит c06a23ea0b
3 изменённых файлов: 99 добавлений и 20 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package utils
import (
"os"
"testing"
)
@@ -12,3 +13,49 @@ func TestConfig(t *testing.T) {
LoadConfig("config.json")
InitTranslations(Cfg.LocalizationSettings)
}
func TestConfigFromEnviroVars(t *testing.T) {
os.Setenv("MM_TEAMSETTINGS_SITENAME", "From Enviroment")
os.Setenv("MM_TEAMSETTINGS_CUSTOMBRANDTEXT", "Custom Brand")
os.Setenv("MM_SERVICESETTINGS_ENABLECOMMANDS", "false")
os.Setenv("MM_SERVICESETTINGS_READTIMEOUT", "400")
TranslationsPreInit()
EnableConfigFromEnviromentVars()
LoadConfig("config.json")
if Cfg.TeamSettings.SiteName != "From Enviroment" {
t.Fatal("Couldn't read config from enviroment var")
}
if *Cfg.TeamSettings.CustomBrandText != "Custom Brand" {
t.Fatal("Couldn't read config from enviroment var")
}
if *Cfg.ServiceSettings.EnableCommands != false {
t.Fatal("Couldn't read config from enviroment var")
}
if *Cfg.ServiceSettings.ReadTimeout != 400 {
t.Fatal("Couldn't read config from enviroment var")
}
os.Unsetenv("MM_TEAMSETTINGS_SITENAME")
os.Unsetenv("MM_TEAMSETTINGS_CUSTOMBRANDTEXT")
os.Unsetenv("MM_SERVICESETTINGS_ENABLECOMMANDS")
os.Unsetenv("MM_SERVICESETTINGS_READTIMEOUT")
Cfg.TeamSettings.SiteName = "Mattermost"
*Cfg.ServiceSettings.SiteURL = ""
*Cfg.ServiceSettings.EnableCommands = true
*Cfg.ServiceSettings.ReadTimeout = 300
SaveConfig(CfgFileName, Cfg)
LoadConfig("config.json")
if Cfg.TeamSettings.SiteName != "Mattermost" {
t.Fatal("should have been reset")
}
}