MM-10730 Added support for empty environment variables to viper (#8973)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
1f65f0e3d6
Коммит
07c785e294
@@ -335,6 +335,9 @@ func TestConfigFromEnviroVars(t *testing.T) {
|
||||
"TeamSettings": {
|
||||
"SiteName": "Mattermost",
|
||||
"CustomBrandText": ""
|
||||
},
|
||||
"SupportSettings": {
|
||||
"TermsOfServiceLink": "https://about.mattermost.com/default-terms/"
|
||||
}
|
||||
}`
|
||||
|
||||
@@ -447,6 +450,28 @@ func TestConfigFromEnviroVars(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("empty string setting", func(t *testing.T) {
|
||||
os.Setenv("MM_SUPPORTSETTINGS_TERMSOFSERVICELINK", "")
|
||||
defer os.Unsetenv("MM_SUPPORTSETTINGS_TERMSOFSERVICELINK")
|
||||
|
||||
cfg, envCfg, err := ReadConfig(strings.NewReader(config), true)
|
||||
require.Nil(t, err)
|
||||
|
||||
if *cfg.SupportSettings.TermsOfServiceLink != "" {
|
||||
t.Fatal("Couldn't read empty TermsOfServiceLink from environment var")
|
||||
}
|
||||
|
||||
if supportSettings, ok := envCfg["SupportSettings"]; !ok {
|
||||
t.Fatal("SupportSettings is missing from envConfig")
|
||||
} else if supportSettingsAsMap, ok := supportSettings.(map[string]interface{}); !ok {
|
||||
t.Fatal("SupportSettings is not a map in envConfig")
|
||||
} else {
|
||||
if termsOfServiceLinkInEnv, ok := supportSettingsAsMap["TermsOfServiceLink"].(bool); !ok || !termsOfServiceLinkInEnv {
|
||||
t.Fatal("TermsOfServiceLink should be in envConfig")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestValidateLocales(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user