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

Simplify tests with T.TempDir #929

Merged

Conversation

alexandear
Copy link
Contributor

@alexandear alexandear commented Jan 31, 2025

Describe the change

The PR refactors tests that contain os.MkdirTemp and os.Remove with T.TempDir. That allows to remove 50 lines of test code without harming readability.
Also, enables usetesting to automatically detect this in the future.

Describe your solution

The PR replaces usages of CreateTestDirectory with t.TempDir(). It's not needed to call os.Remove anymore.

Additional context

TempDir returns a temporary directory for the test to use. The directory is automatically removed when the test and all its subtests complete.

@alexandear alexandear force-pushed the refactor/simplify-tests branch from b8d72d3 to 92275d1 Compare January 31, 2025 17:36
@alexandear alexandear force-pushed the refactor/simplify-tests branch from 92275d1 to 04e8437 Compare January 31, 2025 17:40
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.69%. Comparing base (774fc9d) to head (04e8437).
Report is 79 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #929      +/-   ##
==========================================
+ Coverage   98.46%   98.69%   +0.23%     
==========================================
  Files          24       26       +2     
  Lines        1364     1761     +397     
==========================================
+ Hits         1343     1738     +395     
- Misses         15       16       +1     
- Partials        6        7       +1     

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

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

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

Great work, thank you so much!

@sashabaranov sashabaranov merged commit 7a2915a into sashabaranov:master Jan 31, 2025
3 checks passed
@alexandear alexandear deleted the refactor/simplify-tests branch January 31, 2025 19:05
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