Skip to content

Commit 3a2298b

Browse files
pkg/env: IsSet returns true if EnvKey has a value
1 parent 71cf473 commit 3a2298b

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎env/env.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ func SetEnvOn() {
5555

5656
// IsSet returns if the given env key is set.
5757
func IsSet(key string) bool {
58-
_, _, _, err := LookupEnv(key)
59-
return err == nil
58+
return Get(key, "") != ""
6059
}
6160

6261
// Get retrieves the value of the environment variable named
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ func TestWebEnv(t *testing.T) {
8989
}
9090
}
9191

92+
func TestIsSet(t *testing.T) {
93+
os.Setenv("_TEST_ENV", "")
94+
defer os.Unsetenv("_TEST_ENV")
95+
96+
if IsSet("_TEST_ENV") {
97+
t.Fatal("Expected IsSet(false) but found IsSet(true)")
98+
}
99+
100+
os.Setenv("_TEST_ENV", "v")
101+
if !IsSet("_TEST_ENV") {
102+
t.Fatal("Expected IsSet(true) but found IsSet(false)")
103+
}
104+
}
105+
92106
func TestGetEnv(t *testing.T) {
93107
// Set empty env-value, this test covers situation
94108
// where env is set but with empty value, choose

0 commit comments

Comments
 (0)