// Test when parsing env variables into a struct. // It should set the env values into the structure. func TestEnvironmentValues(t *testing.T) { stringVar := "string value" intVar := 6789 floatVar := float32(1234.56) boolVar := true s := &SupportedTypes{} os.Setenv("STRING_VAR", stringVar) os.Setenv("INT_VAR", fmt.Sprintf("%d", intVar)) os.Setenv("FLOAT_VAR", fmt.Sprintf("%f", floatVar)) os.Setenv("BOOL_VAR", fmt.Sprintf("%t", boolVar)) defer func() { syscall.Clearenv() }() if err := env.Parse(s); err != nil { t.Fatal(err.Error()) } if s.BoolType != boolVar { t.Errorf("Test env values: bool value was not set properly. Expected: [%v] but was [%v]", boolVar, s.BoolType) } if s.FloatType != floatVar { t.Errorf("Test env values: float value was not set properly. Expected: [%v] but was [%v]", floatVar, s.FloatType) } if s.IntType != intVar { t.Errorf("Test env values: int value was not set properly. Expected: [%v] but was [%v]", intVar, s.IntType) } if s.StringType != stringVar { t.Errorf("Test env values: string value was not set properly. Expected: [%v] but was [%v]", stringVar, s.StringType) } }
// Clearenv deletes all environment variables. func Clearenv() { syscall.Clearenv() }
// Clearenv deletes all environment variables. func Clearenv() { // 删除所有的环境变量 syscall.Clearenv() }