Skip to content
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

test: use T.Setenv to set env vars in tests #6037

Merged
merged 1 commit into from
Aug 19, 2022
Merged

test: use T.Setenv to set env vars in tests #6037

merged 1 commit into from
Aug 19, 2022

Conversation

Juneezee
Copy link
Contributor

What type of PR is this:

/kind cleanup

What does this PR do / why we need it:

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.

This saves us at least 2 lines (error check, and unsetting the env var) on every instance.

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

Which issue(s) this PR fixes:

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

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 <[email protected]>
@openshift-ci
Copy link

openshift-ci bot commented Aug 18, 2022

@Juneezee: The label(s) kind/cleanup cannot be applied, because the repository doesn't have them.

In response to this:

What type of PR is this:

/kind cleanup

What does this PR do / why we need it:

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.

This saves us at least 2 lines (error check, and unsetting the env var) on every instance.

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

Which issue(s) this PR fixes:

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@netlify
Copy link

netlify bot commented Aug 18, 2022

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit eefc841
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/62fe44b552caa500083104ce

@openshift-ci openshift-ci bot requested review from dharmit and valaparthvi August 18, 2022 13:55
@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. Required by Prow. label Aug 18, 2022
@openshift-ci
Copy link

openshift-ci bot commented Aug 18, 2022

Hi @Juneezee. Thanks for your PR.

I'm waiting for a redhat-developer member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@odo-robot
Copy link

odo-robot bot commented Aug 18, 2022

Windows Tests (OCP) on commit finished with errors.
View logs: TXT HTML

@valaparthvi
Copy link
Contributor

/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. Required by Prow. labels Aug 18, 2022
@odo-robot
Copy link

odo-robot bot commented Aug 18, 2022

Unit Tests on commit finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Aug 18, 2022

Validate Tests on commit finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Aug 18, 2022

OpenShift Tests on commit finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Aug 18, 2022

Kubernetes Tests on commit finished successfully.
View logs: TXT HTML

@feloy
Copy link
Contributor

feloy commented Aug 19, 2022

Thanks @Juneezee for these changes

/lgtm
/approve

/override windows-integration-test/Windows-test

@openshift-ci
Copy link

openshift-ci bot commented Aug 19, 2022

@feloy: Overrode contexts on behalf of feloy: windows-integration-test/Windows-test

In response to this:

Thanks @Juneezee for these changes

/lgtm
/approve

/override windows-integration-test/Windows-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Aug 19, 2022
@openshift-ci
Copy link

openshift-ci bot commented Aug 19, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feloy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Aug 19, 2022
@valaparthvi
Copy link
Contributor

/override ci/prow/v4.10-integration-e2e

@openshift-ci
Copy link

openshift-ci bot commented Aug 19, 2022

@valaparthvi: Overrode contexts on behalf of valaparthvi: ci/prow/v4.10-integration-e2e

In response to this:

/override ci/prow/v4.10-integration-e2e

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-merge-robot openshift-merge-robot merged commit 53a733b into redhat-developer:main Aug 19, 2022
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
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 <[email protected]>

Signed-off-by: Eng Zer Jun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. lgtm Indicates that a PR is ready to be merged. Required by Prow. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants