blockchain: Use TempDir to create temp test dirs.#2902
blockchain: Use TempDir to create temp test dirs.#2902davecgh merged 2 commits intodecred:masterfrom Juneezee:test/t.TempDir
Conversation
davecgh
left a comment
There was a problem hiding this comment.
Thanks for the PR.
I haven't fully reviewed this yet, but I did notice a couple of things that will ultimately end up needing quite a few changes so I wanted to go ahead and call those out now.
T.TempDir to create temporary test directoryThere was a problem hiding this comment.
Thanks for the updates. Everything looks good to go now. It's nice to see changes that result in less code without losing any functionality and making the tests less prone to forgetting to cleanup.
I pointed out a minor thing you might want to update as well, but it's optional, so I've approved it regardless.
The directory created by `T.TempDir` is automatically removed when the test and all its subtests complete. This commit also refactor several cleanup logic by using `t.Cleanup` instead of `defer`. Reference: https://pkg.go.dev/testing#T.TempDir Reference: https://pkg.go.dev/testing#T.Cleanup Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
|
Just an FYI that I squashed this down into a single commit with a |
A testing cleanup.
We can use the
T.TempDirfunction from thetestingpackage to create temporary directory. The directory created byT.TempDiris automatically removed when the test and all its subtests complete.This PR also refactor several cleanup logic by using
t.Cleanupinstead ofdefer.Reference: https://pkg.go.dev/testing#T.TempDir
Reference: https://pkg.go.dev/testing#T.Cleanup