Merge remote-tracking branch 'upstream/release-5.2' into release-5.2-daily-merge-20180810
Этот коммит содержится в:
@@ -41,11 +41,15 @@ func jobserverCmdF(command *cobra.Command, args []string) {
|
|||||||
|
|
||||||
// Run jobs
|
// Run jobs
|
||||||
mlog.Info("Starting Mattermost job server")
|
mlog.Info("Starting Mattermost job server")
|
||||||
|
defer mlog.Info("Stopped Mattermost job server")
|
||||||
|
|
||||||
if !noJobs {
|
if !noJobs {
|
||||||
a.Jobs.StartWorkers()
|
a.Jobs.StartWorkers()
|
||||||
|
defer a.Jobs.StopWorkers()
|
||||||
}
|
}
|
||||||
if !noSchedule {
|
if !noSchedule {
|
||||||
a.Jobs.StartSchedulers()
|
a.Jobs.StartSchedulers()
|
||||||
|
defer a.Jobs.StopSchedulers()
|
||||||
}
|
}
|
||||||
|
|
||||||
signalChan := make(chan os.Signal, 1)
|
signalChan := make(chan os.Signal, 1)
|
||||||
@@ -54,9 +58,4 @@ func jobserverCmdF(command *cobra.Command, args []string) {
|
|||||||
|
|
||||||
// Cleanup anything that isn't handled by a defer statement
|
// Cleanup anything that isn't handled by a defer statement
|
||||||
mlog.Info("Stopping Mattermost job server")
|
mlog.Info("Stopping Mattermost job server")
|
||||||
|
|
||||||
a.Jobs.StopSchedulers()
|
|
||||||
a.Jobs.StopWorkers()
|
|
||||||
|
|
||||||
mlog.Info("Stopped Mattermost job server")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,9 +181,11 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform
|
|||||||
|
|
||||||
if *a.Config().JobSettings.RunJobs {
|
if *a.Config().JobSettings.RunJobs {
|
||||||
a.Jobs.StartWorkers()
|
a.Jobs.StartWorkers()
|
||||||
|
defer a.Jobs.StopWorkers()
|
||||||
}
|
}
|
||||||
if *a.Config().JobSettings.RunScheduler {
|
if *a.Config().JobSettings.RunScheduler {
|
||||||
a.Jobs.StartSchedulers()
|
a.Jobs.StartSchedulers()
|
||||||
|
defer a.Jobs.StopSchedulers()
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyReady()
|
notifyReady()
|
||||||
@@ -201,9 +203,6 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform
|
|||||||
a.Metrics.StopServer()
|
a.Metrics.StopServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
a.Jobs.StopSchedulers()
|
|
||||||
a.Jobs.StopWorkers()
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -247,12 +247,6 @@ func ReadConfig(r io.Reader, allowEnvironmentOverrides bool) (*model.Config, map
|
|||||||
|
|
||||||
var config model.Config
|
var config model.Config
|
||||||
unmarshalErr := v.Unmarshal(&config)
|
unmarshalErr := v.Unmarshal(&config)
|
||||||
if unmarshalErr == nil {
|
|
||||||
// https://github.com/spf13/viper/issues/324
|
|
||||||
// https://github.com/spf13/viper/issues/348
|
|
||||||
config.PluginSettings = model.PluginSettings{}
|
|
||||||
unmarshalErr = v.UnmarshalKey("pluginsettings", &config.PluginSettings)
|
|
||||||
}
|
|
||||||
|
|
||||||
envConfig := v.EnvSettings()
|
envConfig := v.EnvSettings()
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,49 @@ func TestReadConfig(t *testing.T) {
|
|||||||
require.EqualError(t, err, "parsing error at line 3, character 5: invalid character 'm' looking for beginning of object key string")
|
require.EqualError(t, err, "parsing error at line 3, character 5: invalid character 'm' looking for beginning of object key string")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadConfig_PluginSettings(t *testing.T) {
|
||||||
|
TranslationsPreInit()
|
||||||
|
|
||||||
|
config, _, err := ReadConfig(bytes.NewReader([]byte(`{
|
||||||
|
"PluginSettings": {
|
||||||
|
"Directory": "/temp/mattermost-plugins",
|
||||||
|
"Plugins": {
|
||||||
|
"com.example.plugin": {
|
||||||
|
"number": 1,
|
||||||
|
"string": "abc",
|
||||||
|
"boolean": false,
|
||||||
|
"abc.def.ghi": {
|
||||||
|
"abc": 123,
|
||||||
|
"def": "456"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"PluginStates": {
|
||||||
|
"com.example.plugin": {
|
||||||
|
"enable": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`)), false)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, "/temp/mattermost-plugins", *config.PluginSettings.Directory)
|
||||||
|
assert.Contains(t, config.PluginSettings.Plugins, "com.example.plugin")
|
||||||
|
assert.Equal(t, map[string]interface{}{
|
||||||
|
"number": float64(1),
|
||||||
|
"string": "abc",
|
||||||
|
"boolean": false,
|
||||||
|
"abc.def.ghi": map[string]interface{}{
|
||||||
|
"abc": float64(123),
|
||||||
|
"def": "456",
|
||||||
|
},
|
||||||
|
}, config.PluginSettings.Plugins["com.example.plugin"])
|
||||||
|
assert.Contains(t, config.PluginSettings.PluginStates, "com.example.plugin")
|
||||||
|
assert.Equal(t, model.PluginState{
|
||||||
|
Enable: true,
|
||||||
|
}, *config.PluginSettings.PluginStates["com.example.plugin"])
|
||||||
|
}
|
||||||
|
|
||||||
func TestTimezoneConfig(t *testing.T) {
|
func TestTimezoneConfig(t *testing.T) {
|
||||||
TranslationsPreInit()
|
TranslationsPreInit()
|
||||||
supportedTimezones := LoadTimezones("timezones.json")
|
supportedTimezones := LoadTimezones("timezones.json")
|
||||||
@@ -472,6 +515,36 @@ func TestConfigFromEnviroVars(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("plugin directory settings", func(t *testing.T) {
|
||||||
|
os.Setenv("MM_PLUGINSETTINGS_DIRECTORY", "/temp/plugins")
|
||||||
|
os.Setenv("MM_PLUGINSETTINGS_CLIENTDIRECTORY", "/temp/clientplugins")
|
||||||
|
defer os.Unsetenv("MM_PLUGINSETTINGS_DIRECTORY")
|
||||||
|
defer os.Unsetenv("MM_PLUGINSETTINGS_CLIENTDIRECTORY")
|
||||||
|
|
||||||
|
cfg, envCfg, err := ReadConfig(strings.NewReader(config), true)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
if *cfg.PluginSettings.Directory != "/temp/plugins" {
|
||||||
|
t.Fatal("Couldn't read Directory from environment var")
|
||||||
|
}
|
||||||
|
if *cfg.PluginSettings.ClientDirectory != "/temp/clientplugins" {
|
||||||
|
t.Fatal("Couldn't read ClientDirectory from environment var")
|
||||||
|
}
|
||||||
|
|
||||||
|
if pluginSettings, ok := envCfg["PluginSettings"]; !ok {
|
||||||
|
t.Fatal("PluginSettings is missing from envConfig")
|
||||||
|
} else if pluginSettingsAsMap, ok := pluginSettings.(map[string]interface{}); !ok {
|
||||||
|
t.Fatal("PluginSettings is not a map in envConfig")
|
||||||
|
} else {
|
||||||
|
if directory, ok := pluginSettingsAsMap["Directory"].(bool); !ok || !directory {
|
||||||
|
t.Fatal("Directory should be in envConfig")
|
||||||
|
}
|
||||||
|
if clientDirectory, ok := pluginSettingsAsMap["ClientDirectory"].(bool); !ok || !clientDirectory {
|
||||||
|
t.Fatal("ClientDirectory should be in envConfig")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateLocales(t *testing.T) {
|
func TestValidateLocales(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user