mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
refactor: use t.TempDir() instead of os.MkdirTemp (#1484)
Signed-off-by: linchizhen <jiayanbing@yeah.net>
This commit is contained in:
parent
d72c039a1a
commit
a2fe0aaa2e
4 changed files with 9 additions and 27 deletions
|
|
@ -61,14 +61,7 @@ func TestMain(m *testing.M) {
|
||||||
func runClef(t *testing.T, args ...string) *testproc {
|
func runClef(t *testing.T, args ...string) *testproc {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
ddir, err := os.MkdirTemp("", "cleftest-*")
|
ddir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Cleanup(func() {
|
|
||||||
os.RemoveAll(ddir)
|
|
||||||
})
|
|
||||||
|
|
||||||
return runWithKeystore(t, ddir, args...)
|
return runWithKeystore(t, ddir, args...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,11 +87,7 @@ func TestHistoryImportAndExport(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make temp directory for era files.
|
// Make temp directory for era files.
|
||||||
dir, err := os.MkdirTemp("", "history-export-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("error creating temp test directory: %v", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
// Export history to temp directory.
|
// Export history to temp directory.
|
||||||
if err := ExportHistory(chain, dir, 0, count, step); err != nil {
|
if err := ExportHistory(chain, dir, 0, count, step); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -332,8 +332,7 @@ func TestOpenDrops(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// Create a temporary folder for the persistent backend
|
// Create a temporary folder for the persistent backend
|
||||||
storage, _ := os.MkdirTemp("", "blobpool-")
|
storage := t.TempDir()
|
||||||
defer os.RemoveAll(storage)
|
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
||||||
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
||||||
|
|
@ -655,8 +654,7 @@ func TestOpenIndex(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// Create a temporary folder for the persistent backend
|
// Create a temporary folder for the persistent backend
|
||||||
storage, _ := os.MkdirTemp("", "blobpool-")
|
storage := t.TempDir()
|
||||||
defer os.RemoveAll(storage)
|
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
||||||
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
||||||
|
|
@ -744,8 +742,7 @@ func TestOpenHeap(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// Create a temporary folder for the persistent backend
|
// Create a temporary folder for the persistent backend
|
||||||
storage, _ := os.MkdirTemp("", "blobpool-")
|
storage := t.TempDir()
|
||||||
defer os.RemoveAll(storage)
|
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
||||||
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
||||||
|
|
@ -831,8 +828,8 @@ func TestOpenCap(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// Create a temporary folder for the persistent backend
|
// 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)
|
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
||||||
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
||||||
|
|
@ -1286,8 +1283,7 @@ func TestAdd(t *testing.T) {
|
||||||
}
|
}
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
// Create a temporary folder for the persistent backend
|
// Create a temporary folder for the persistent backend
|
||||||
storage, _ := os.MkdirTemp("", "blobpool-")
|
storage := t.TempDir()
|
||||||
defer os.RemoveAll(storage) // late defer, still ok
|
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
os.MkdirAll(filepath.Join(storage, pendingTransactionStore), 0700)
|
||||||
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
store, _ := billy.Open(billy.Options{Path: filepath.Join(storage, pendingTransactionStore)}, newSlotter(), nil)
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,7 @@ func TestOfflineBlockPrune(t *testing.T) {
|
||||||
func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64) {
|
func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
datadir, err := os.MkdirTemp("", "")
|
datadir := t.TempDir()
|
||||||
require.NoError(t, err, "failed to create temporary datadir")
|
|
||||||
|
|
||||||
os.RemoveAll(datadir)
|
|
||||||
|
|
||||||
chaindbPath := filepath.Join(datadir, "chaindata")
|
chaindbPath := filepath.Join(datadir, "chaindata")
|
||||||
oldAncientPath := filepath.Join(chaindbPath, "ancient")
|
oldAncientPath := filepath.Join(chaindbPath, "ancient")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue