-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: use T.TempDir
to create temporary test directory
#13644
Conversation
The directory created by `T.TempDir()` and is automatically removed when the test and all its subtests complete. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the change! Thanks
cc @ptabor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the improvement.
t.Fatal(err) | ||
} | ||
tmpdirs[i] = d | ||
tmpdirs[i] = t.TempDir() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In such situation where we have meaningful identifier in the directory name that points on the instance of etcd from the test I would prefer to preserve it in the path.
rootTmpDir=t.TempDir()
for i := range peers {
d, err := os.MkdirTemp(rootTmpDir, fmt.Sprintf("%d-%d.etcd", i, e2e.EtcdProcessBasePort+i))
}
This makes it easier to correlate logs (and path in the logs) with a directory that might contain a corrupted state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!! Thanks @Juneezee
We can write less code by using the
T.TempDir
function from thetesting
package to create temporary test directory. The directory created byT.TempDir
is automatically removed when the test and all its subtests complete.Reference: https://pkg.go.dev/testing#T.TempDir