Refactor tests to use t.TempDir and cleanup go.mod deps - #123
Conversation
Replaces manual temporary directory and file management in tests with t.TempDir() for improved reliability and automatic cleanup. Removes unnecessary os.RemoveAll and similar cleanup calls. Updates go.mod to remove github.com/docker/docker and move github.com/moby/sys/reexec to a direct dependency.
There was a problem hiding this comment.
Pull Request Overview
Refactors tests to use t.TempDir() and t.Setenv() for cleaner resource and environment handling, and adds the usetesting linter to enforce idiomatic testing patterns. Also adjusts module dependencies by removing github.com/docker/docker and making github.com/moby/sys/reexec a direct dependency.
- Replace manual temp dir and env var management with testing helpers (t.TempDir, t.Setenv)
- Add usetesting linter to .golangci.yml
- Update go.mod dependencies (remove docker/docker; promote moby/sys/reexec to direct)
Reviewed Changes
Copilot reviewed 53 out of 54 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| signer/storage/aes_gcm_storage_test.go | Replaced manual temp dir setup with t.TempDir |
| signer/fourbyte/fourbyte_test.go | Removed os import and used t.TempDir |
| signer/core/api_test.go | Simplified tmpDirName to use t.TempDir |
| rpc/security_test.go | Switched to t.Setenv but left redundant cleanup |
| rpc/client_test.go | Switched to t.Setenv but left redundant cleanup |
| raft/*.go tests | Replaced manual temp dir creation/cleanup with t.TempDir |
| private/private_test.go | Switched to t.Setenv |
| plugin/*_test.go | Adopted t.TempDir and t.Setenv patterns |
| permission/* tests | Replaced manual temp dir handling with t.TempDir |
| p2p/* tests | Adopted t.TempDir and minor variable handling updates |
| node/* tests | Replaced manual temp dir logic with t.TempDir |
| internal/* tests | Updated to t.TempDir / t.Setenv patterns |
| graphql/graphql_test.go | Simplified temp dir usage |
| extension/data_handler_test.go | Replaced manual temp dir logic with t.TempDir |
| eth/filters/filter_test.go | Used b.TempDir / t.TempDir for benchmarks and tests |
| crypto/* tests | Updated temp file creation to reside under t.TempDir |
| core/* tests | Broad refactor to use t.TempDir; some semantics changed where dirs were previously removed immediately |
| console/console_test.go | Replaced manual workspace cleanup with t.TempDir |
| common/http/config_test.go | Used t.TempDir for config files |
| cmd/utils/flags_test.go | Adopted t.TempDir |
| cmd/geth/* tests | Mixed changes; one cleanup path removal introduces a resource leak |
| accounts/keystore/* tests | Migrated helper functions to t.TempDir |
| accounts/abi/bind/bind_test.go | Simplified workspace creation with t.TempDir |
| .golangci.yml | Added usetesting linter |
| go.mod | Removed docker/docker and promoted moby/sys/reexec to direct dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 53 out of 54 changed files in this pull request and generated 6 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
close #122
This pull request refactors the test codebase to use Go's
t.TempDir()for managing temporary directories instead of manually creating and cleaning up directories withos.MkdirTempandos.RemoveAll. This change simplifies test setup and teardown, reduces boilerplate, and makes the tests more robust and idiomatic. Additionally, a new linter (usetesting) is added to the configuration to encourage best practices in using thetestingpackage.Key changes include:
Testing improvements
os.MkdirTempandos.RemoveAll) witht.TempDir()across all test files.Linter configuration
usetestinglinter to.golangci.ymlto enforce and encourage idiomatic usage of the Gotestingpackage, such as preferringt.TempDir()over manual directory management.