Skip to content

blockchain: Use TempDir to create temp test dirs.#2902

Merged
davecgh merged 2 commits intodecred:masterfrom
Juneezee:test/t.TempDir
Mar 18, 2022
Merged

blockchain: Use TempDir to create temp test dirs.#2902
davecgh merged 2 commits intodecred:masterfrom
Juneezee:test/t.TempDir

Conversation

@Juneezee
Copy link
Copy Markdown
Contributor

@Juneezee Juneezee commented Mar 17, 2022

A testing cleanup.

We can use the T.TempDir function from the testing package to create temporary directory. The directory created by T.TempDir is automatically removed when the test and all its subtests complete.

This PR 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

Copy link
Copy Markdown
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

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.

Comment thread blockchain/common_test.go
Comment thread blockchain/common_test.go
@davecgh davecgh changed the title test: use T.TempDir to create temporary test directory multi: Use TempDir to create temp test dirs. Mar 17, 2022
Comment thread blockchain/common_test.go
@Juneezee Juneezee requested a review from davecgh March 17, 2022 03:51
Copy link
Copy Markdown
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

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.

Comment thread blockchain/indexers/spendconsumer_test.go Outdated
Comment thread blockchain/common_test.go
Comment thread blockchain/common_test.go
Comment thread blockchain/common_test.go
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>
@davecgh davecgh added this to the 1.8.0 milestone Mar 17, 2022
@davecgh davecgh changed the title multi: Use TempDir to create temp test dirs. blockchain: Use TempDir to create temp test dirs. Mar 18, 2022
@davecgh davecgh merged commit fccb811 into decred:master Mar 18, 2022
@davecgh
Copy link
Copy Markdown
Member

davecgh commented Mar 18, 2022

Just an FYI that I squashed this down into a single commit with a blockchain prefix since test is not one of the prefixes in use and it really is 99.9% directed at blockchain.

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.

3 participants