package forward import ( "os" "testing" ) func TestEnvBool(t *testing.T) { t.Setenv("TEST_ENV_BOOL", "") if envBool("TEST_ENV_BOOL", true) != true { t.Fatal("empty should use default true") } if envBool("TEST_ENV_BOOL", false) != false { t.Fatal("empty should use default false") } for _, v := range []string{"false", "FALSE", "0", "no", "NO", "off", "OFF"} { t.Setenv("TEST_ENV_BOOL", v) if envBool("TEST_ENV_BOOL", true) { t.Fatalf("%q should be false", v) } } for _, v := range []string{"true", "1", "yes", "on"} { t.Setenv("TEST_ENV_BOOL", v) if !envBool("TEST_ENV_BOOL", false) { t.Fatalf("%q should be true", v) } } } func TestEnvString(t *testing.T) { const key = "TEST_ENV_STRING_XK" _ = os.Unsetenv(key) if env(key, "default") != "default" { t.Fatal("unset should return default") } t.Setenv(key, " value ") if env(key, "default") != "value" { t.Fatal("should trim spaces") } }