lotusdb icon indicating copy to clipboard operation
lotusdb copied to clipboard

test: use `T.TempDir` to create temporary test directory

Open Juneezee opened this issue 2 years ago • 3 comments

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()
}

Juneezee avatar Jun 19 '22 07:06 Juneezee

Can you test it in Windows environment? In windows we maybe encounter some problems when we delete the files.

roseduan avatar Jul 02 '22 11:07 roseduan

Marking this PR as draft first before https://github.com/flower-corp/lotusdb/pull/46 is merged.

Juneezee avatar Jul 02 '22 12:07 Juneezee

Hi @roseduan, please take a look at this PR as well after merging #46 . I'll rebase once #46 has been merged. Thank you.

Juneezee avatar Aug 21 '22 18:08 Juneezee

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

Juneezee avatar Apr 19 '23 02:04 Juneezee

friendly ping @roseduan

Juneezee avatar Jun 08 '23 15:06 Juneezee

I will rebuild the whole project and do more changes, please follow me the V2 version. Thanks for your support!

roseduan avatar Jun 26 '23 11:06 roseduan