Skip to content

test: make createTestDir a general test utility #832

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

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented Feb 28, 2024

We've already got this duplicated in two places, and I have need for it in an upcoming PR and @robramsaynz should be using it in #797 so let's move this into testutility

@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 72.72727% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 59.70%. Comparing base (b28c1c8) to head (8c427dc).
Report is 2 commits behind head on main.

Files Patch % Lines
internal/testutility/utility.go 72.72% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #832      +/-   ##
==========================================
- Coverage   59.78%   59.70%   -0.09%     
==========================================
  Files         136      136              
  Lines       11268    11279      +11     
==========================================
- Hits         6737     6734       -3     
- Misses       4102     4115      +13     
- Partials      429      430       +1     

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

Comment on lines 61 to 65
// CreateTestDir makes a temporary directory for use in testing that involves
// writing and reading files from disk - make sure to call the cleanup function!
func CreateTestDir(t *testing.T) (string, func()) {
t.Helper()
Copy link
Contributor

@spencerschrock spencerschrock Feb 29, 2024

Choose a reason for hiding this comment

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

Happened to see this while checking on another PR here.
t.Cleanup would be helpful here. no need to make caller remember to call cleanup function.

Or there's also just t.TempDir in the stdlib already

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh nice - and yeah I just realised t.TempDir is a thing though sadly it doesn't support a prefix which I personally like to easily identify and manually clean up in the case of a failure or debugging.

Oh well, still probably best to just switch to using that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok after playing with t.TempDir I'm not going to use it for now because we need to be able to normalize the test directory for snapshots, which is too hard with t.TempDir right now 😞

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds reasonable. At least t.Cleanup sounds useful in this case.

Copy link
Collaborator

@another-rex another-rex left a comment

Choose a reason for hiding this comment

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

Thanks!

@another-rex another-rex merged commit a8d55d0 into google:main Mar 4, 2024
@G-Rath G-Rath deleted the make-temp-util branch March 4, 2024 22:57
another-rex pushed a commit that referenced this pull request Mar 4, 2024
When doing #832 I leaned `t.Cleanup` is a thing so let's use that
instead here
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.

4 participants