-
Notifications
You must be signed in to change notification settings - Fork 177
Add the auth.ProcessEnv function
#2404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
31b7ad0
bf234c4
42f6ecf
f559322
a426930
5574563
8283d61
fe11a8f
c456c55
32de708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,19 +13,11 @@ import ( | |
| // The original environment is restored upon test completion. | ||
| // Note: use of this function is incompatible with parallel execution. | ||
| func CleanupEnvironment(t TestingT) { | ||
| // Restore environment when test finishes. | ||
| environ := os.Environ() | ||
| t.Cleanup(func() { | ||
| // Restore original environment. | ||
| for _, kv := range environ { | ||
| kvs := strings.SplitN(kv, "=", 2) | ||
| os.Setenv(kvs[0], kvs[1]) | ||
| } | ||
| }) | ||
|
|
||
| path := os.Getenv("PATH") | ||
| pwd := os.Getenv("PWD") | ||
| os.Clearenv() | ||
|
|
||
| // Clear all environment variables. | ||
| NullEnvironment(t) | ||
|
|
||
| // We use t.Setenv instead of os.Setenv because the former actively | ||
| // prevents a test being run with t.Parallel. Modifying the environment | ||
|
|
@@ -38,6 +30,23 @@ func CleanupEnvironment(t TestingT) { | |
| } | ||
| } | ||
|
|
||
| // NullEnvironment sets up an empty environment with absolutely no environment variables set. | ||
| // The original environment is restored upon test completion. | ||
| // Note: use of this function is incompatible with parallel execution | ||
| func NullEnvironment(t TestingT) { | ||
| // Restore environment when test finishes. | ||
| environ := os.Environ() | ||
| t.Cleanup(func() { | ||
| // Restore original environment. | ||
| for _, kv := range environ { | ||
| kvs := strings.SplitN(kv, "=", 2) | ||
| os.Setenv(kvs[0], kvs[1]) | ||
| } | ||
| }) | ||
|
|
||
| os.Clearenv() | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain the nuance between the two different cleanup functions? The distinction is not clear from the name (cleanup vs clear).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed this to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think NullEnvironment should follow naming of os.Clearenv() since that's essentially a wrapper: Clearenv(t* testing.T). CleanupEnvironment can be renamed to SetMinimalEnvVars? However, I'd rather we did not do this in tests, this feels like it could break things. |
||
| // Changes into specified directory for the duration of the test. | ||
| // Returns the current working directory. | ||
| func Chdir(t TestingT, dir string) string { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.