The source project of this merge request has been removed.
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.
Reference: https://pkg.go.dev/testing#T.TempDir
func TestFoo(t *testing.T) {
// before
tmpDir, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer require.NoError(os.RemoveAll(tmpDir))
// now
tmpDir := t.TempDir()
}
Edited by Eng Zer Jun