This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7f0a64
commit 7a15570
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package env | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGetEnvBool(t *testing.T) { | ||
envVarTestKey := "WAYPOINT_GET_ENV_BOOL_TEST" | ||
require := require.New(t) | ||
|
||
t.Run("Unset env var returns default", func (t *testing.T) { | ||
require.True(GetEnvBool(envVarTestKey, true)) | ||
require.False(GetEnvBool(envVarTestKey, false)) | ||
}) | ||
|
||
t.Run("Empty env var returns default", func (t *testing.T) { | ||
os.Setenv(envVarTestKey, "") | ||
require.True(GetEnvBool(envVarTestKey, true)) | ||
require.False(GetEnvBool(envVarTestKey, false)) | ||
}) | ||
|
||
t.Run("Non-truthy env var returns true", func (t *testing.T) { | ||
os.Setenv(envVarTestKey, "unparseable") | ||
require.True(GetEnvBool(envVarTestKey, true)) | ||
require.False(GetEnvBool(envVarTestKey, false)) | ||
}) | ||
|
||
t.Run("true/false env vars return non-default", func (t *testing.T) { | ||
os.Setenv(envVarTestKey, "true") | ||
require.True(GetEnvBool(envVarTestKey, false)) | ||
|
||
os.Setenv(envVarTestKey, "false") | ||
require.False(GetEnvBool(envVarTestKey, true)) | ||
}) | ||
|
||
t.Run("1 evaluates as true", func (t *testing.T) { | ||
os.Setenv(envVarTestKey, "1") | ||
require.True(GetEnvBool(envVarTestKey, false)) | ||
}) | ||
} |