Beispiel #1
0
// 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)
	}

}
Beispiel #2
0
// Clearenv deletes all environment variables.
func Clearenv() {
	syscall.Clearenv()
}
Beispiel #3
0
// Clearenv deletes all environment variables.
func Clearenv() { // 删除所有的环境变量
	syscall.Clearenv()
}