package envutil // env_test.go contains backend tests for package behavior, error paths, and regressions. import ( "testing" "time" "github.com/stretchr/testify/require" ) // TestString ensures string behavior is handled correctly. func TestString(t *testing.T) { t.Setenv("APP_VALUE", "configured") require.Equal(t, "configured", String("APP_VALUE", "fallback")) } // TestStringFallback ensures string fallback behavior is handled correctly. func TestStringFallback(t *testing.T) { t.Setenv("APP_VALUE", "") require.Equal(t, "fallback", String("APP_VALUE", "fallback")) } // TestInt ensures int behavior is handled correctly. func TestInt(t *testing.T) { t.Setenv("APP_PORT", "8080") require.Equal(t, 8080, Int("APP_PORT", 3000)) } // TestIntFallbackInvalid ensures int fallback invalid behavior is handled correctly. func TestIntFallbackInvalid(t *testing.T) { t.Setenv("APP_PORT", "oops") require.Equal(t, 3000, Int("APP_PORT", 3000)) } // TestDuration ensures duration behavior is handled correctly. func TestDuration(t *testing.T) { t.Setenv("APP_TIMEOUT", "7s") require.Equal(t, 7*time.Second, Duration("APP_TIMEOUT", time.Second)) } // TestDurationFallbackInvalid ensures duration fallback invalid behavior is handled correctly. func TestDurationFallbackInvalid(t *testing.T) { t.Setenv("APP_TIMEOUT", "oops") require.Equal(t, 2*time.Second, Duration("APP_TIMEOUT", 2*time.Second)) }