-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Replace os.TempDir usage with t.TempDir #1146
Conversation
Current tests can leave files around if tests fail, and even though they use rand, it's not seeded, different runs can share the same output file which causes other failures (e.g., file exists when it's not expected to). Avoid this by using t.TempDir which automatically removed after tests have run.
Codecov Report
@@ Coverage Diff @@
## master #1146 +/- ##
=======================================
Coverage 98.32% 98.32%
=======================================
Files 49 49
Lines 2146 2146
=======================================
Hits 2110 2110
Misses 28 28
Partials 8 8 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Instead of managing the environment variable manually, use t.Setenv to set and restore its value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm minus one missed case. will fix
@@ -30,7 +30,7 @@ import ( | |||
|
|||
func BenchmarkBufferedWriteSyncer(b *testing.B) { | |||
b.Run("write file with buffer", func(b *testing.B) { | |||
file, err := os.CreateTemp("", "log") | |||
file, err := os.CreateTemp("", "test.log") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't this use b.TempDir()?
file, err := os.CreateTemp("", "test.log") | |
file, err := os.CreateTemp(b.TempDir(), "test.log") |
Current tests can leave files around if tests fail, and even though they
use rand, it's not seeded, different runs can share the same output file
which causes other failures (e.g., file exists when it's not expected
to). Avoid this by using t.TempDir which automatically removed after
tests have run.