-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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.TempDir
to create temporary test directory
#21043
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
silverwind
approved these changes
Sep 3, 2022
GiteaBot
added
the
lgtm/need 1
This PR needs approval from one additional maintainer to be merged.
label
Sep 3, 2022
Please run |
delvh
approved these changes
Sep 3, 2022
GiteaBot
added
lgtm/done
This PR has enough approvals to get merged. There are no important open reservations anymore.
and removed
lgtm/need 1
This PR needs approval from one additional maintainer to be merged.
labels
Sep 3, 2022
This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `os.MkdirTemp` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <[email protected]>
Ah! This was added in go1.15 which is why we never used it before. Good catch! |
We probably need to update our integration-tests to pre-delete the |
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Sep 5, 2022
* upstream/main: (22 commits) [skip ci] Updated translations via Crowdin Webhook for Wiki changes (go-gitea#20219) test: use `T.TempDir` to create temporary test directory (go-gitea#21043) Set uploadpack.allowFilter etc on gitea serv to enable partial clones with ssh (go-gitea#20902) Fix 500 on time tracking in timeline API (go-gitea#21052) Add more checks in migration code (go-gitea#21011) Fill the specified ref in webhook test payload (go-gitea#20961) [skip ci] Updated licenses and gitignores Add go licenses to licenses.txt (go-gitea#21034) Added docs for agit-setup (go-gitea#21027) Add another index for Action table on postgres (go-gitea#21033) Delete unreferenced packages when deleting a package version (go-gitea#20977) Improve arc-green code theme (go-gitea#21039) Add down key check has tribute container (go-gitea#21016) Do not add links to Posters or Assignees with ID < 0 (go-gitea#20577) [skip ci] Updated translations via Crowdin Show language name on hover (go-gitea#20923) fix: PackageMetadataVersion deps (go-gitea#21017) Fix the quick-submit for pending review comment (go-gitea#20992) Kd/ci playwright go test (go-gitea#20123) ...
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
lgtm/done
This PR has enough approvals to get merged. There are no important open reservations anymore.
type/testing
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A testing cleanup.
This pull request replaces
os.MkdirTemp
witht.TempDir
. We can use theT.TempDir
function from thetesting
package to create temporary directory. The directory created byT.TempDir
is automatically removed when the test and all its subtests complete.This saves us at least 2 lines (error check, and cleanup) on every instance, or in some cases adds cleanup that we forgot.
Reference: https://pkg.go.dev/testing#T.TempDir