mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Validating config on set command (#9914)
* Validating config on set command * Adding more tests to confg set command
This commit is contained in:
@@ -261,6 +261,15 @@ func configSetCmdF(command *cobra.Command, args []string) error {
|
||||
// update the config
|
||||
app.UpdateConfig(f)
|
||||
|
||||
// Verify new config
|
||||
if err := newConfig.IsValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := utils.ValidateLocales(app.Config()); err != nil {
|
||||
return errors.New("Invalid locale configuration")
|
||||
}
|
||||
|
||||
// make the changes persist
|
||||
app.PersistConfig()
|
||||
|
||||
|
||||
@@ -109,6 +109,49 @@ func TestConfigGet(t *testing.T) {
|
||||
assert.Contains(t, string(output), "ExportFromTimestamp")
|
||||
}
|
||||
|
||||
func TestConfigSet(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
path := filepath.Join(dir, "config.json")
|
||||
config := &model.Config{}
|
||||
config.SetDefaults()
|
||||
require.NoError(t, ioutil.WriteFile(path, []byte(config.ToJson()), 0600))
|
||||
|
||||
// Error when no arguments are given
|
||||
assert.Error(t, RunCommand(t, "--config", path, "config", "set"))
|
||||
|
||||
// Error when only one argument is given
|
||||
assert.Error(t, RunCommand(t, "--config", path, "config", "set", "test"))
|
||||
|
||||
// Error when the wrong key is set
|
||||
assert.Error(t, RunCommand(t, "--config", path, "config", "set", "invalid-key", "value"))
|
||||
assert.Error(t, RunCommand(t, "--config", path, "config", "get", "invalid-key"))
|
||||
|
||||
// Error when the wrong value is set
|
||||
assert.Error(t, RunCommand(t, "--config", path, "config", "set", "EmailSettings.ConnectionSecurity", "invalid"))
|
||||
output := CheckCommand(t, "--config", path, "config", "get", "EmailSettings.ConnectionSecurity")
|
||||
assert.NotContains(t, string(output), "invalid")
|
||||
|
||||
// Error when the wrong locale is set
|
||||
assert.NoError(t, RunCommand(t, "--config", path, "config", "set", "LocalizationSettings.DefaultServerLocale", "es"))
|
||||
assert.Error(t, RunCommand(t, "--config", path, "config", "set", "LocalizationSettings.DefaultServerLocale", "invalid"))
|
||||
output = CheckCommand(t, "--config", path, "config", "get", "LocalizationSettings.DefaultServerLocale")
|
||||
assert.NotContains(t, string(output), "invalid")
|
||||
assert.NotContains(t, string(output), "\"en\"")
|
||||
|
||||
// Success when a valid value is set
|
||||
assert.NoError(t, RunCommand(t, "--config", path, "config", "set", "EmailSettings.ConnectionSecurity", "TLS"))
|
||||
output = CheckCommand(t, "--config", path, "config", "get", "EmailSettings.ConnectionSecurity")
|
||||
assert.Contains(t, string(output), "TLS")
|
||||
|
||||
// Success when a valid locale is set
|
||||
assert.NoError(t, RunCommand(t, "--config", path, "config", "set", "LocalizationSettings.DefaultServerLocale", "es"))
|
||||
output = CheckCommand(t, "--config", path, "config", "get", "LocalizationSettings.DefaultServerLocale")
|
||||
assert.Contains(t, string(output), "\"es\"")
|
||||
}
|
||||
|
||||
func TestStructToMap(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
|
||||
Reference in New Issue
Block a user