You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package envutil
|
|
|
|
// env_test.go contains tests for backend behavior.
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestString verifies expected behavior.
|
|
func TestString(t *testing.T) {
|
|
t.Setenv("APP_VALUE", "configured")
|
|
require.Equal(t, "configured", String("APP_VALUE", "fallback"))
|
|
}
|
|
|
|
// TestStringFallback verifies expected behavior.
|
|
func TestStringFallback(t *testing.T) {
|
|
t.Setenv("APP_VALUE", "")
|
|
require.Equal(t, "fallback", String("APP_VALUE", "fallback"))
|
|
}
|
|
|
|
// TestInt verifies expected behavior.
|
|
func TestInt(t *testing.T) {
|
|
t.Setenv("APP_PORT", "8080")
|
|
require.Equal(t, 8080, Int("APP_PORT", 3000))
|
|
}
|
|
|
|
// TestIntFallbackInvalid verifies expected behavior.
|
|
func TestIntFallbackInvalid(t *testing.T) {
|
|
t.Setenv("APP_PORT", "oops")
|
|
require.Equal(t, 3000, Int("APP_PORT", 3000))
|
|
}
|
|
|
|
// TestDuration verifies expected behavior.
|
|
func TestDuration(t *testing.T) {
|
|
t.Setenv("APP_TIMEOUT", "7s")
|
|
require.Equal(t, 7*time.Second, Duration("APP_TIMEOUT", time.Second))
|
|
}
|
|
|
|
// TestDurationFallbackInvalid verifies expected behavior.
|
|
func TestDurationFallbackInvalid(t *testing.T) {
|
|
t.Setenv("APP_TIMEOUT", "oops")
|
|
require.Equal(t, 2*time.Second, Duration("APP_TIMEOUT", 2*time.Second))
|
|
}
|