lotusdb
lotusdb copied to clipboard
test: use `T.TempDir` to create temporary test directory
A testing cleanup.
This pull request replaces ioutil.TempDir
with t.TempDir
. 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 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
func TestFoo(t *testing.T) {
// before
tmpDir, err := ioutil.TempDir("", "")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)
// now
tmpDir := t.TempDir()
}
Can you test it in Windows environment? In windows we maybe encounter some problems when we delete the files.
Marking this PR as draft first before https://github.com/flower-corp/lotusdb/pull/46 is merged.
Hi @roseduan, please take a look at this PR as well after merging #46 . I'll rebase once #46 has been merged. Thank you.
Hi @roseduan, it's been a while since this PR was last reviewed. Would you mind taking a few minutes again and possibly merge it? Thanks in advance
friendly ping @roseduan
I will rebuild the whole project and do more changes, please follow me the V2 version. Thanks for your support!