Skip to content

Commit

Permalink
Merge pull request #30 from upsight/bugfix/envparent
Browse files Browse the repository at this point in the history
Changes the behavior of env parent to child
  • Loading branch information
pkar authored Nov 13, 2017
2 parents 2c10044 + afa868b commit 861c1cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions target/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ func (e *Env) process() error {
e.config[k] = os.Expand(e.config[k], e.Getenv)
}
if e.parent != nil {
// set the parent envs here as final values.
// set the final envs from parent here as final
// only if the value is empty.
for k, v := range e.parent.Env.config {
e.config[k] = v
if e.config[k] == "" {
e.config[k] = v
}
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions target/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestEnv_processParentFile(t *testing.T) {
eParent, err := NewEnv(nil, &RawConfig{Envs: ""}, ParseOSEnvs([]string{"APP=don", "HELLO=goodbye", "ABC=+pwd"}), writer)
ok(t, err)
f := &File{Env: eParent}
e, err := NewEnv(f, &RawConfig{Envs: ""}, ParseOSEnvs([]string{"APP=ron", "HELLO=hello", "ABC=+pwd"}), writer)
e, err := NewEnv(f, &RawConfig{Envs: ""}, ParseOSEnvs([]string{"APP=", "HELLO=hello", "ABC=+pwd"}), writer)
ok(t, err)
err = e.process()
ok(t, err)
Expand All @@ -95,7 +95,7 @@ func TestEnv_processParentFile(t *testing.T) {
want := `don`
equals(t, want, got)
got = c["HELLO"]
want = `goodbye`
want = `hello`
equals(t, want, got)
}

Expand Down

0 comments on commit 861c1cd

Please sign in to comment.