-
Notifications
You must be signed in to change notification settings - Fork 125
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
#647
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
Hello @sfc-gh-dszmolka @sfc-gh-igarish . I apologize for the explicit mention, but I wanted to follow up on this pull request I created some time ago. I would be grateful if you could take some time to review the changes and provide me with your feedback. If there are any specific concerns or questions you have about the changes, I am more than willing to help address them. Thank you for your time and consideration. I truly appreciate it. ❤️ |
@Juneezee In original code it was using pattern (the second argument) in each MkdirTemp call. How the replacement call works for the same? |
@sfc-gh-igarish |
friendly ping @sfc-gh-igarish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi @sfc-gh-igarish, please re-run the failing tests. I think the failing tests are not related to this PR. Thanks. |
@Juneezee Please update the branch. Even if it's not related to this PR, it's a merge gate. I will try again once you update the branch. |
@Juneezee These are the failures, which I believe related to this PR: |
Windows handle open files differently so we need to close all open file descriptors explicitly. I've found a few places where we missed adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This commit replaces `ioutil.TempDir` 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 `ioutil.TempDir` 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]>
This commit fixes the 3 failing tests on Windows [1] 1. TestEncryptDecryptFilePadding 2. TestEncryptDecryptLargeFile 3. TestPutGetFile They all failed with the same reason: testing.go:1097: TempDir RemoveAll cleanup: remove ... The process cannot access the file because it is being used by another process. Windows handle open files differently [2] so we need to close all open file descriptors explicitly. [1]: https://github.com/snowflakedb/gosnowflake/actions/runs/5214296899/jobs/9410395563?pr=647 [2]: golang/go#50510 (comment) Signed-off-by: Eng Zer Jun <[email protected]>
Reference: https://github.com/snowflakedb/gosnowflake/pull/647/files#r1233553225 Signed-off-by: Eng Zer Jun <[email protected]>
Thank you very much @Juneezee for your input! I merged your PR :) |
Description
A testing cleanup.
This pull request replaces
ioutil.TempDir
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
Checklist
make fmt
to fix inconsistent formatsmake lint
to get lint errors and fix all of them