Documentation
¶
Overview ¶
Package env provides functions to test code that read environment variables or the current working directory.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeWorkingDir ¶
ChangeWorkingDir to the directory, and return a function which restores the previous working directory.
When used with Go 1.14+ the previous working directory will be restored automatically when the test ends, unless the TEST_NOCLEANUP env var is set to true.
func Patch
deprecated
Patch changes the value of an environment variable, and returns a function which will reset the the value of that variable back to the previous state.
When used with Go 1.14+ the unpatch function will be called automatically when the test ends, unless the TEST_NOCLEANUP env var is set to true.
Deprecated: use t.SetEnv
Example ¶
Patch an environment variable and defer to return to the previous state
defer Patch(t, "PATH", "/custom/path")()
Output:
func PatchAll ¶
PatchAll sets the environment to env, and returns a function which will reset the environment back to the previous state.
When used with Go 1.14+ the unpatch function will be called automatically when the test ends, unless the TEST_NOCLEANUP env var is set to true.
Example ¶
Patch all environment variables
defer PatchAll(t, map[string]string{ "ONE": "FOO", "TWO": "BAR", })()
Output:
Types ¶
This section is empty.