Skip to content

Refactor tests to use t.TempDir and cleanup go.mod deps - #123

Merged
YoshihitoAso merged 2 commits into
dev-2.6from
feature/#122
Sep 22, 2025
Merged

Refactor tests to use t.TempDir and cleanup go.mod deps#123
YoshihitoAso merged 2 commits into
dev-2.6from
feature/#122

Conversation

@YoshihitoAso

@YoshihitoAso YoshihitoAso commented Sep 19, 2025

Copy link
Copy Markdown
Member

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 with os.MkdirTemp and os.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 the testing package.

Key changes include:

Testing improvements

  • Replaced manual temporary directory management (os.MkdirTemp and os.RemoveAll) with t.TempDir() across all test files.

Linter configuration

  • Added the usetesting linter to .golangci.yml to enforce and encourage idiomatic usage of the Go testing package, such as preferring t.TempDir() over manual directory management.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread cmd/geth/run_test.go
Comment thread rpc/security_test.go Outdated
Comment thread rpc/client_test.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread internal/build/util_test.go
Comment thread internal/build/util_test.go
Comment thread core/bench_test.go
Comment thread core/bench_test.go
Comment thread core/bench_test.go
Comment thread cmd/geth/run_test.go
@YoshihitoAso
YoshihitoAso marked this pull request as ready for review September 19, 2025 11:51
@YoshihitoAso
YoshihitoAso merged commit a679261 into dev-2.6 Sep 22, 2025
5 checks passed
@YoshihitoAso
YoshihitoAso deleted the feature/#122 branch September 22, 2025 01:29
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.

[FEATURE] use T.TempDir to create temporary test directories

2 participants