-
Notifications
You must be signed in to change notification settings - Fork 2.2k
test: use T.TempDir
to create temporary test directory
#6710
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
Conversation
Rebased onto |
Rebased onto |
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.
Thanks a lot for the cleanup PR!
I think it makes a lot of sense to make use of this new feature.
To make review easier, would it be possible for you to split this PR into multiple commits, one for each top level package (aliasmgr, cert, chainntnfs, chanbackup, channeldb, ...
) and prefix the commits accordingly?
Also an entry in the 0.16 change log file under the "Code health" section (you can create it if it doesn't exist yet) would be nice.
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.
Wow, that was quick! Thanks a lot for the updates.
Looks very good to me. Did a quick search after checking out this PR and found 7 more instances of ioutil.TempFile
throughout the codebase. Do we want to fix those as well?
Since it seems mixing t.TempDir()
and ioutil.TempFile()
can lead to errors.
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.
Thanks a lot for the updates!
Can you work the last two commits into their corresponding previous commits please? Basically split the commits and squash them with the commit for the package they belong in.
Then I'll do a full review on it again.
@@ -434,7 +433,7 @@ func TestChangeWalletPasswordNewRootkey(t *testing.T) { | |||
// requested. | |||
var tempFiles []string | |||
for i := 0; i < 3; i++ { | |||
file, err := ioutil.TempFile(testDir, "") | |||
file, err := os.CreateTemp(testDir, "") |
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.
Hmm, this doesn't seem to fix the flaky failure I mentioned before. It looks like you uncovered a problem with the test itself.
We need to add require.NoError(t, unlockMsg.UnloadWallet())
on Line 608 (directly after service.MacResponseChan <- testMac
) to fix the flake.
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.
Thanks for the blazing fast updates! LGTM 🎉
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.
Very nice! I also like bringing the usage of t.Cleanup
, which makes everything cleaner. This is an LGTM👍 Meanwhile, could you rebase this PR? We've added an extra build step and kinda wanna see if this PR passes.
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
Signed-off-by: Eng Zer Jun <[email protected]>
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🎉
Change 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
Steps to Test
Changes to existing tests only. The existing testing targets in Makefile and CI cover the changes.
Pull Request Checklist
Testing
Tests covering the positive and negative (error paths) are included.Bug fixes contain tests triggering the bug to prevent regressions.Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.