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

Backport of test: use T.TempDir to create temporary test directory into release/1.3.x #12966

Conversation

hc-github-team-nomad-core
Copy link
Contributor

Backport

This PR is auto-generated from #12853 to be assessed for backporting due to the inclusion of the label backport/1.3.x.

The below text is copied from the body of the original PR.


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("", "")
	require.NoError(t, err)
	defer require.NoError(t, os.RemoveAll(tmpDir))

	// now
	tmpDir := t.TempDir()
}

Related PR in Terraform: hashicorp/terraform#30803

@hc-github-team-nomad-core hc-github-team-nomad-core force-pushed the backport/test/t.TempDir/uniquely-romantic-mallard branch from cdcda5f to 9a3418f Compare May 12, 2022 15:43
@hc-github-team-nomad-core hc-github-team-nomad-core merged commit b47797d into release/1.3.x May 12, 2022
@hc-github-team-nomad-core hc-github-team-nomad-core deleted the backport/test/t.TempDir/uniquely-romantic-mallard branch May 12, 2022 15:43
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants