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

[tests]: Use t.TempDir to create temporary test directory #4613

Merged
merged 1 commit into from
Aug 1, 2023
Merged

[tests]: Use t.TempDir to create temporary test directory #4613

merged 1 commit into from
Aug 1, 2023

Conversation

Juneezee
Copy link
Contributor

@Juneezee Juneezee commented Aug 1, 2023

Which problem is this PR solving?

Short description of the changes

This pull request replaces os.MkdirTemp 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
	dir, err := os.MkdirTemp("", "")
	require.NoError(t, err)
	defer os.RemoveAll(dir)

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

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]>
@Juneezee Juneezee requested a review from a team as a code owner August 1, 2023 12:34
@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (82e426c) 97.07% compared to head (86bff50) 97.07%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4613   +/-   ##
=======================================
  Coverage   97.07%   97.07%           
=======================================
  Files         301      301           
  Lines       17876    17876           
=======================================
  Hits        17353    17353           
  Misses        419      419           
  Partials      104      104           
Flag Coverage Δ
unittests 97.07% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

thx

@yurishkuro yurishkuro merged commit 32f3252 into jaegertracing:main Aug 1, 2023
31 checks passed
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.

2 participants