diff --git a/env.go b/env.go index 2a6e086ab..29aeba19d 100644 --- a/env.go +++ b/env.go @@ -10,8 +10,8 @@ type Env struct { // It returns the value, or the default (or an emptry string) if the variable is // not set. func (e *Env) Getenv(key string, def ...string) string { - val, ok := os.LookupEnv(key) - if !ok && len(def) > 0 { + val := os.Getenv(key) + if val == "" && len(def) > 0 { return def[0] } diff --git a/test/integration/envvars.bats b/test/integration/envvars.bats index 6bec5695a..c8a69dddc 100644 --- a/test/integration/envvars.bats +++ b/test/integration/envvars.bats @@ -27,6 +27,12 @@ load helper [[ "${output}" == "foo" ]] } +@test "default string with empty env var using getenv" { + FOO="" gomplate -i '{{getenv "FOO" "foo"}}' + [ "$status" -eq 0 ] + [[ "${output}" == "foo" ]] +} + @test "existant env var using .Env" { gomplate -i '{{.Env.HOME}}' [ "$status" -eq 0 ]