Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Tests perbrian's suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
izaaklauer committed Jun 23, 2021
1 parent c7f0a64 commit 7a15570
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/env/env_test.go
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))
})
}

0 comments on commit 7a15570

Please sign in to comment.