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 and t.TempDir #668

Merged
merged 1 commit into from
Apr 11, 2023
Merged

test: use t.Setenv and t.TempDir #668

merged 1 commit into from
Apr 11, 2023

Conversation

Juneezee
Copy link
Contributor

What this PR does / why we need it:

This commit replaces:
1. os.Setenv with t.Setenv
2. os.MkdirTemp with t.TempDir

With t.Setenv, the environment variable is automatically restored to its original value when the test and all its subtests complete.

The directory created by t.TempDir is automatically removed when the test and all its subtests complete.

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

Which issue(s) this PR fixes:

Special notes for your reviewer:

@Juneezee Juneezee requested a review from a team as a code owner April 10, 2023 16:20
@Juneezee Juneezee requested review from wbrowne and andresmgot and removed request for a team April 10, 2023 16:20
@CLAassistant
Copy link

CLAassistant commented Apr 10, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This commit replaces:
	1. `os.Setenv` with `t.Setenv`
	2. `os.MkdirTemp` with `t.TempDir`

With `t.Setenv`, the environment variable is automatically restored to
its original value when the test and all its subtests complete.

The directory created by `t.TempDir` is automatically removed when the
test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@andresmgot andresmgot merged commit 7b5e7ca into grafana:main Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants