Skip to content
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

Merged
merged 1 commit into from
Feb 21, 2022
Merged

*: use T.TempDir to create temporary test directory #13644

merged 1 commit into from
Feb 21, 2022

Conversation

Juneezee
Copy link
Contributor

We can write less code by using the T.TempDir function from the testing package to create temporary test 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

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>
Copy link
Member

@serathius serathius left a 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

@serathius
Copy link
Member

cc @ptabor

Copy link
Member

@ahrtr ahrtr left a 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()
Copy link
Contributor

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.

Copy link
Member

@spzala spzala left a comment

Choose a reason for hiding this comment

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

Nice!! Thanks @Juneezee

@ptabor ptabor merged commit f80f477 into etcd-io:main Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants