From 07c785e294e70494ae6016d59749a71af3f74920 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 21 Jun 2018 10:30:20 -0400 Subject: MM-10730 Added support for empty environment variables to viper (#8973) --- utils/config_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'utils') diff --git a/utils/config_test.go b/utils/config_test.go index 278f24251..80ab05ffe 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -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) { -- cgit v1.2.3-1-g7c22