Skip to content

Conversation

Juneezee
Copy link
Contributor

@Juneezee Juneezee commented Jan 2, 2023

This PR replaces os.Setenv with t.Setenv. Starting from Go 1.17, we can use t.Setenv to set environment variable in test. The environment variable is automatically restored to its original value when the test and all its subtests complete. This ensures that each test does not start with leftover environment variables from previous completed tests.

Reference: https://pkg.go.dev/testing#T.Setenv

func TestFoo(t *testing.T) { // before os.Setenv(key, "new value") defer os.Unsetenv(key) // after t.Setenv(key, "new value") }

All Submissions:

  • Have you opened an Issue before filing this PR?
  • Have you signed our CLA?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Put closes #XXXX in your comment to auto-close the issue that your PR fixes (if such).
This commit replaces `os.Setenv` with `t.Setenv` in tests. The environment variable is automatically restored to its original value when the test and all its subtests complete. Reference: https://pkg.go.dev/testing#T.Setenv Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
@slaskawi slaskawi added the safe-to-test Add this label to PRs from forks to trigger E2E tests label Jan 4, 2023
@slaskawi slaskawi self-assigned this Jan 4, 2023
@slaskawi slaskawi merged commit dffad0d into mongodb:master Jan 5, 2023
@slaskawi
Copy link
Contributor

slaskawi commented Jan 5, 2023

Integrated, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-test Add this label to PRs from forks to trigger E2E tests

2 participants