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

test: use T.TempDir to create temporary test directory #3560

Merged
merged 2 commits into from
Feb 11, 2023
Merged

Conversation

sparrc
Copy link
Contributor

@sparrc sparrc commented Feb 7, 2023

NOTE: this is a cherry-pick of commit from #3159, and I've added a commit to fix windows integ test build.

From the original PR:

This commit replaces os.MkdirTemp with t.TempDir in tests. The directory created by t.TempDir is automatically removed when the test and all its subtests complete.

Prior to this commit, temporary directory created using os.MkdirTemp needs to be removed manually by calling os.RemoveAll, which is omitted in some tests. The error handling boilerplate e.g.

	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}

is also tedious, but t.TempDir handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun [email protected]

closes #3159

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `os.MkdirTemp`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <[email protected]>
@sparrc sparrc merged commit bccbb18 into aws:dev Feb 11, 2023
@sparrc sparrc deleted the pr-3159 branch February 11, 2023 03:51
@YashdalfTheGray YashdalfTheGray mentioned this pull request Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants