Example #1
0
// TestEnvVarsSet tests the setting of temporary environment variables.
func TestEnvVarsSet(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	testEnv := func(key, value string) {
		v := os.Getenv(key)
		assert.Equal(v, value)
	}

	ev := audit.NewEnvVars(assert)
	assert.NotNil(ev)
	defer ev.Restore()

	ev.Set("TESTING_ENV_A", "FOO")
	testEnv("TESTING_ENV_A", "FOO")
	ev.Set("TESTING_ENV_B", "BAR")
	testEnv("TESTING_ENV_B", "BAR")

	ev.Unset("TESTING_ENV_A")
	testEnv("TESTING_ENV_A", "")
}
Example #2
0
// TestEnvVarsREstore tests the restoring of temporary set environment
// variables.
func TestEnvVarsRestore(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	testEnv := func(key, value string) {
		v := os.Getenv(key)
		assert.Equal(v, value)
	}

	ev := audit.NewEnvVars(assert)
	assert.NotNil(ev)

	path := os.Getenv("PATH")
	assert.NotEmpty(path)

	ev.Set("PATH", "/foo:/bar/bin")
	testEnv("PATH", "/foo:/bar/bin")
	ev.Set("PATH", "/bar:/foo:/yadda/bin")
	testEnv("PATH", "/bar:/foo:/yadda/bin")

	ev.Restore()

	testEnv("PATH", path)
}