Skip to content

Commit d103f17

Browse files
authored
build: replace tenv linter with usetesting (#31172)
1 parent cb9653d commit d103f17

File tree

9 files changed

+20
-43
lines changed

9 files changed

+20
-43
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ linters:
2525
- gocheckcompilerdirectives
2626
- reassign
2727
- mirror
28-
- tenv
28+
- usetesting
2929
### linters we tried and will not be using:
3030
###
3131
# - structcheck # lots of false positives

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ archives are published at https://geth.ethereum.org/downloads/.
1616

1717
For prerequisites and detailed build instructions please read the [Installation Instructions](https://geth.ethereum.org/docs/getting-started/installing-geth).
1818

19-
Building `geth` requires both a Go (version 1.22 or later) and a C compiler. You can install
19+
Building `geth` requires both a Go (version 1.23 or later) and a C compiler. You can install
2020
them using your favourite package manager. Once the dependencies are installed, run
2121

2222
```shell

cmd/clef/run_test.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ func TestMain(m *testing.M) {
5757
// This method creates a temporary keystore folder which will be removed after
5858
// the test exits.
5959
func runClef(t *testing.T, args ...string) *testproc {
60-
ddir, err := os.MkdirTemp("", "cleftest-*")
61-
if err != nil {
62-
return nil
63-
}
64-
t.Cleanup(func() {
65-
os.RemoveAll(ddir)
66-
})
60+
ddir := t.TempDir()
6761
return runWithKeystore(t, ddir, args...)
6862
}
6963

cmd/utils/history_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ func TestHistoryImportAndExport(t *testing.T) {
8787
}
8888

8989
// Make temp directory for era files.
90-
dir, err := os.MkdirTemp("", "history-export-test")
91-
if err != nil {
92-
t.Fatalf("error creating temp test directory: %v", err)
93-
}
94-
defer os.RemoveAll(dir)
90+
dir := t.TempDir()
9591

9692
// Export history to temp directory.
9793
if err := ExportHistory(chain, dir, 0, count, step); err != nil {

core/txpool/blobpool/blobpool_test.go

+7-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"crypto/ecdsa"
2222
"crypto/sha256"
2323
"errors"
24+
"fmt"
2425
"math"
2526
"math/big"
2627
"os"
@@ -452,8 +453,7 @@ func TestOpenDrops(t *testing.T) {
452453
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
453454

454455
// Create a temporary folder for the persistent backend
455-
storage, _ := os.MkdirTemp("", "blobpool-")
456-
defer os.RemoveAll(storage)
456+
storage := t.TempDir()
457457

458458
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
459459
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(testMaxBlobsPerBlock), nil)
@@ -775,8 +775,7 @@ func TestOpenIndex(t *testing.T) {
775775
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
776776

777777
// Create a temporary folder for the persistent backend
778-
storage, _ := os.MkdirTemp("", "blobpool-")
779-
defer os.RemoveAll(storage)
778+
storage := t.TempDir()
780779

781780
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
782781
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(testMaxBlobsPerBlock), nil)
@@ -864,8 +863,7 @@ func TestOpenHeap(t *testing.T) {
864863
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
865864

866865
// Create a temporary folder for the persistent backend
867-
storage, _ := os.MkdirTemp("", "blobpool-")
868-
defer os.RemoveAll(storage)
866+
storage := t.TempDir()
869867

870868
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
871869
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(testMaxBlobsPerBlock), nil)
@@ -951,8 +949,7 @@ func TestOpenCap(t *testing.T) {
951949
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
952950

953951
// Create a temporary folder for the persistent backend
954-
storage, _ := os.MkdirTemp("", "blobpool-")
955-
defer os.RemoveAll(storage)
952+
storage := t.TempDir()
956953

957954
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
958955
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(testMaxBlobsPerBlock), nil)
@@ -1041,8 +1038,7 @@ func TestChangingSlotterSize(t *testing.T) {
10411038
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
10421039

10431040
// Create a temporary folder for the persistent backend
1044-
storage, _ := os.MkdirTemp("", "blobpool-")
1045-
defer os.RemoveAll(storage)
1041+
storage := t.TempDir()
10461042

10471043
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
10481044
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(6), nil)
@@ -1508,8 +1504,7 @@ func TestAdd(t *testing.T) {
15081504
}
15091505
for i, tt := range tests {
15101506
// Create a temporary folder for the persistent backend
1511-
storage, _ := os.MkdirTemp("", "blobpool-")
1512-
defer os.RemoveAll(storage) // late defer, still ok
1507+
storage := filepath.Join(t.TempDir(), fmt.Sprintf("test-%d", i))
15131508

15141509
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
15151510
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(testMaxBlobsPerBlock), nil)

crypto/crypto_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestLoadECDSA(t *testing.T) {
181181
}
182182

183183
for _, test := range tests {
184-
f, err := os.CreateTemp("", "loadecdsa_test.*.txt")
184+
f, err := os.CreateTemp(t.TempDir(), "loadecdsa_test.*.txt")
185185
if err != nil {
186186
t.Fatal(err)
187187
}
@@ -202,7 +202,7 @@ func TestLoadECDSA(t *testing.T) {
202202
}
203203

204204
func TestSaveECDSA(t *testing.T) {
205-
f, err := os.CreateTemp("", "saveecdsa_test.*.txt")
205+
f, err := os.CreateTemp(t.TempDir(), "saveecdsa_test.*.txt")
206206
if err != nil {
207207
t.Fatal(err)
208208
}

crypto/signify/signify_test.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ var (
3333
)
3434

3535
func TestSignify(t *testing.T) {
36-
tmpFile, err := os.CreateTemp("", "")
36+
tmpFile, err := os.CreateTemp(t.TempDir(), "")
3737
if err != nil {
3838
t.Fatal(err)
3939
}
40-
defer os.Remove(tmpFile.Name())
4140
defer tmpFile.Close()
4241

4342
data := make([]byte, 1024)
@@ -52,7 +51,6 @@ func TestSignify(t *testing.T) {
5251
if err != nil {
5352
t.Fatal(err)
5453
}
55-
defer os.Remove(tmpFile.Name() + ".sig")
5654

5755
// Verify the signature using a golang library
5856
sig, err := minisign.NewSignatureFromFile(tmpFile.Name() + ".sig")
@@ -75,11 +73,10 @@ func TestSignify(t *testing.T) {
7573
}
7674

7775
func TestSignifyTrustedCommentTooManyLines(t *testing.T) {
78-
tmpFile, err := os.CreateTemp("", "")
76+
tmpFile, err := os.CreateTemp(t.TempDir(), "")
7977
if err != nil {
8078
t.Fatal(err)
8179
}
82-
defer os.Remove(tmpFile.Name())
8380
defer tmpFile.Close()
8481

8582
data := make([]byte, 1024)
@@ -94,15 +91,13 @@ func TestSignifyTrustedCommentTooManyLines(t *testing.T) {
9491
if err == nil || err.Error() == "" {
9592
t.Fatalf("should have errored on a multi-line trusted comment, got %v", err)
9693
}
97-
defer os.Remove(tmpFile.Name() + ".sig")
9894
}
9995

10096
func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) {
101-
tmpFile, err := os.CreateTemp("", "")
97+
tmpFile, err := os.CreateTemp(t.TempDir(), "")
10298
if err != nil {
10399
t.Fatal(err)
104100
}
105-
defer os.Remove(tmpFile.Name())
106101
defer tmpFile.Close()
107102

108103
data := make([]byte, 1024)
@@ -117,15 +112,13 @@ func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) {
117112
if err != nil {
118113
t.Fatal(err)
119114
}
120-
defer os.Remove(tmpFile.Name() + ".sig")
121115
}
122116

123117
func TestSignifyTrustedCommentEmpty(t *testing.T) {
124-
tmpFile, err := os.CreateTemp("", "")
118+
tmpFile, err := os.CreateTemp(t.TempDir(), "")
125119
if err != nil {
126120
t.Fatal(err)
127121
}
128-
defer os.Remove(tmpFile.Name())
129122
defer tmpFile.Close()
130123

131124
data := make([]byte, 1024)
@@ -140,5 +133,4 @@ func TestSignifyTrustedCommentEmpty(t *testing.T) {
140133
if err != nil {
141134
t.Fatal(err)
142135
}
143-
defer os.Remove(tmpFile.Name() + ".sig")
144136
}

internal/era/era_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestEra1Builder(t *testing.T) {
3737
t.Parallel()
3838

3939
// Get temp directory.
40-
f, err := os.CreateTemp("", "era1-test")
40+
f, err := os.CreateTemp(t.TempDir(), "era1-test")
4141
if err != nil {
4242
t.Fatalf("error creating temp file: %v", err)
4343
}
@@ -78,6 +78,7 @@ func TestEra1Builder(t *testing.T) {
7878
if err != nil {
7979
t.Fatalf("failed to open era: %v", err)
8080
}
81+
defer e.Close()
8182
it, err := NewRawIterator(e)
8283
if err != nil {
8384
t.Fatalf("failed to make iterator: %s", err)

node/config_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ func TestDatadirCreation(t *testing.T) {
5353
t.Fatalf("freshly created datadir not accessible: %v", err)
5454
}
5555
// Verify that an impossible datadir fails creation
56-
file, err := os.CreateTemp("", "")
56+
file, err := os.CreateTemp(t.TempDir(), "")
5757
if err != nil {
5858
t.Fatalf("failed to create temporary file: %v", err)
5959
}
6060
defer func() {
6161
file.Close()
62-
os.Remove(file.Name())
6362
}()
6463

6564
dir = filepath.Join(file.Name(), "invalid/path")

0 commit comments

Comments
 (0)