eth/tracers: add cleanup for temporary files in bad block trace tests

This commit adds a cleanup function to remove temporary files created during the `TestStandardTraceBadBlockToFile` test. The cleanup is performed using `t.Cleanup` to ensure that files are deleted after the test execution, improving resource management and preventing potential file clutter.

Signed-off-by: katsumata <12413150+winor30@users.noreply.github.com>
This commit is contained in:
katsumata 2025-06-09 21:29:27 +09:00
parent 297c4e7fd1
commit 8b3c88c088
No known key found for this signature in database
GPG key ID: 8987A425F9AD03B0

View file

@ -1516,6 +1516,11 @@ func TestStandardTraceBadBlockToFile(t *testing.T) {
t.Parallel()
files, err := api.StandardTraceBadBlockToFile(context.Background(), tc.badBlockHash, tc.config)
t.Cleanup(func() {
for _, fileName := range files {
os.Remove(fileName)
}
})
// Check error expectations
if tc.expectError {
@ -1552,9 +1557,6 @@ func TestStandardTraceBadBlockToFile(t *testing.T) {
t.Fatalf("Trace file %d content mismatch.\nExpected:\n%s\nGot:\n%s", i, tc.expectedTraces[i], traceContent)
}
}
// Clean up
os.Remove(fileName)
}
})
}