Skip to content

Commit

Permalink
Fixes an issue with env variable is to empty string (#1860)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheikh, Haroon <[email protected]>
  • Loading branch information
haroon-sheikh authored Jan 22, 2021
1 parent 13a8959 commit 3d42444
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func loadEnvDir(envName string) error {
func GetProcessedPropertiesMap(propertiesMap *properties.Properties) (*properties.Properties, error) {
for propertyKey := range propertiesMap.Map() {
// Update properties if an env var is set.
if envVarValue, present := os.LookupEnv(propertyKey); present {
if envVarValue, present := os.LookupEnv(propertyKey); present && len(envVarValue) > 0 {
if _, _, err := propertiesMap.Set(propertyKey, envVarValue); err != nil {
return propertiesMap, fmt.Errorf("%s", err.Error())
}
Expand Down
13 changes: 13 additions & 0 deletions env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ func (s *MySuite) TestLoadDefaultEnvWithSubstitutedVariables(c *C) {
c.Assert(os.Getenv("property2"), Equals, "value1/value2")
}

func (s *MySuite) TestLoadDefaultEmptyEnvWithSubstitutedVariables(c *C) {
os.Clearenv()
os.Setenv("property1", "")

config.ProjectRoot = "_testdata/proj1"

e := LoadEnv(common.DefaultEnvDir, nil)

c.Assert(e, Equals, nil)

c.Assert(os.Getenv("property1"), Equals, "value1")
}

func (s *MySuite) TestLoadDefaultEnvWithMissingSubstitutedVariable(c *C) {
os.Clearenv()
config.ProjectRoot = "_testdata/proj5"
Expand Down

0 comments on commit 3d42444

Please sign in to comment.