Skip to content

Commit

Permalink
build: replace tenv linter with usetesting (ethereum#31172)
Browse files Browse the repository at this point in the history
  • Loading branch information
levisyin authored Feb 21, 2025
1 parent cb9653d commit d103f17
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ linters:
- gocheckcompilerdirectives
- reassign
- mirror
- tenv
- usetesting
### linters we tried and will not be using:
###
# - structcheck # lots of false positives
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ archives are published at https://geth.ethereum.org/downloads/.

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

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

```shell
Expand Down
8 changes: 1 addition & 7 deletions cmd/clef/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ func TestMain(m *testing.M) {
// This method creates a temporary keystore folder which will be removed after
// the test exits.
func runClef(t *testing.T, args ...string) *testproc {
ddir, err := os.MkdirTemp("", "cleftest-*")
if err != nil {
return nil
}
t.Cleanup(func() {
os.RemoveAll(ddir)
})
ddir := t.TempDir()
return runWithKeystore(t, ddir, args...)
}

Expand Down
6 changes: 1 addition & 5 deletions cmd/utils/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ func TestHistoryImportAndExport(t *testing.T) {
}

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

// Export history to temp directory.
if err := ExportHistory(chain, dir, 0, count, step); err != nil {
Expand Down
19 changes: 7 additions & 12 deletions core/txpool/blobpool/blobpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/ecdsa"
"crypto/sha256"
"errors"
"fmt"
"math"
"math/big"
"os"
Expand Down Expand Up @@ -452,8 +453,7 @@ func TestOpenDrops(t *testing.T) {
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))

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

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

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

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

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

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

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

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

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

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

os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(testMaxBlobsPerBlock), nil)
Expand Down
4 changes: 2 additions & 2 deletions crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestLoadECDSA(t *testing.T) {
}

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

func TestSaveECDSA(t *testing.T) {
f, err := os.CreateTemp("", "saveecdsa_test.*.txt")
f, err := os.CreateTemp(t.TempDir(), "saveecdsa_test.*.txt")
if err != nil {
t.Fatal(err)
}
Expand Down
16 changes: 4 additions & 12 deletions crypto/signify/signify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ var (
)

func TestSignify(t *testing.T) {
tmpFile, err := os.CreateTemp("", "")
tmpFile, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()

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

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

func TestSignifyTrustedCommentTooManyLines(t *testing.T) {
tmpFile, err := os.CreateTemp("", "")
tmpFile, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()

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

func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) {
tmpFile, err := os.CreateTemp("", "")
tmpFile, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()

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

func TestSignifyTrustedCommentEmpty(t *testing.T) {
tmpFile, err := os.CreateTemp("", "")
tmpFile, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()

data := make([]byte, 1024)
Expand All @@ -140,5 +133,4 @@ func TestSignifyTrustedCommentEmpty(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile.Name() + ".sig")
}
3 changes: 2 additions & 1 deletion internal/era/era_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestEra1Builder(t *testing.T) {
t.Parallel()

// Get temp directory.
f, err := os.CreateTemp("", "era1-test")
f, err := os.CreateTemp(t.TempDir(), "era1-test")
if err != nil {
t.Fatalf("error creating temp file: %v", err)
}
Expand Down Expand Up @@ -78,6 +78,7 @@ func TestEra1Builder(t *testing.T) {
if err != nil {
t.Fatalf("failed to open era: %v", err)
}
defer e.Close()
it, err := NewRawIterator(e)
if err != nil {
t.Fatalf("failed to make iterator: %s", err)
Expand Down
3 changes: 1 addition & 2 deletions node/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ func TestDatadirCreation(t *testing.T) {
t.Fatalf("freshly created datadir not accessible: %v", err)
}
// Verify that an impossible datadir fails creation
file, err := os.CreateTemp("", "")
file, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatalf("failed to create temporary file: %v", err)
}
defer func() {
file.Close()
os.Remove(file.Name())
}()

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

0 comments on commit d103f17

Please sign in to comment.