Replace os.MkdirTemp with t.TempDir #327

Merged
fyrchik merged 1 commit from ale64bit/frostfs-node:tests/remove-mkdir-temp into master 2023-05-05 11:24:52 +00:00
6 changed files with 9 additions and 36 deletions

View file

@ -2,7 +2,6 @@ package blobstor
import (
"context"
"os"
"testing"
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
@ -15,13 +14,9 @@ import (
)
func TestExists(t *testing.T) {
dir, err := os.MkdirTemp("", "frostfs*")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(dir) })
const smallSizeLimit = 512
storages, _, largeFileStorage := defaultTestStorages(dir, smallSizeLimit)
storages, _, largeFileStorage := defaultTestStorages(t.TempDir(), smallSizeLimit)
b := New(WithStorages(storages))

View file

@ -3,7 +3,6 @@ package blobstor
import (
"context"
"fmt"
"os"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
@ -21,18 +20,13 @@ type storage struct {
}
func (s storage) open(b *testing.B) common.Storage {
dir, err := os.MkdirTemp(os.TempDir(), s.desc)
if err != nil {
b.Fatalf("creating %s root path: %v", s.desc, err)
}
st := s.create(dir)
st := s.create(b.TempDir())
require.NoError(b, st.Open(false))
require.NoError(b, st.Init())
b.Cleanup(func() {
require.NoError(b, st.Close())
require.NoError(b, os.RemoveAll(dir))
})
return st

View file

@ -233,8 +233,7 @@ func TestExecBlocks(t *testing.T) {
}
func TestPersistentShardID(t *testing.T) {
dir, err := os.MkdirTemp("", "*")
require.NoError(t, err)
dir := t.TempDir()
te := newEngineWithErrorThreshold(t, dir, 1)

View file

@ -41,11 +41,7 @@ type testShard struct {
func newEngineWithErrorThreshold(t testing.TB, dir string, errThreshold uint32) *testEngine {
if dir == "" {
var err error
dir, err = os.MkdirTemp("", "*")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(dir) })
dir = t.TempDir()
}
var testShards [2]*testShard
@ -171,9 +167,7 @@ func TestErrorReporting(t *testing.T) {
}
func TestBlobstorFailback(t *testing.T) {
dir, err := os.MkdirTemp("", "*")
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, os.RemoveAll(dir)) })
dir := t.TempDir()
te := newEngineWithErrorThreshold(t, dir, 1)
@ -185,7 +179,7 @@ func TestBlobstorFailback(t *testing.T) {
var prm shard.PutPrm
prm.SetObject(obj)
te.ng.mtx.RLock()
_, err = te.ng.shards[te.shards[0].id.String()].Shard.Put(context.Background(), prm)
_, err := te.ng.shards[te.shards[0].id.String()].Shard.Put(context.Background(), prm)
te.ng.mtx.RUnlock()
require.NoError(t, err)
objs = append(objs, obj)
@ -193,7 +187,7 @@ func TestBlobstorFailback(t *testing.T) {
for i := range objs {
addr := object.AddressOf(objs[i])
_, err = te.ng.Get(context.Background(), GetPrm{addr: addr})
_, err := te.ng.Get(context.Background(), GetPrm{addr: addr})
require.NoError(t, err)
_, err = te.ng.GetRange(context.Background(), RngPrm{addr: addr})
require.NoError(t, err)

View file

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strconv"
"testing"
@ -25,9 +24,7 @@ import (
)
func newEngineEvacuate(t *testing.T, shardNum int, objPerShard int) (*StorageEngine, []*shard.ID, []*objectSDK.Object) {
dir, err := os.MkdirTemp("", "*")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(dir) })
dir := t.TempDir()
te := testNewEngine(t, WithShardPoolSize(1)).
setShardsNumOpts(t, shardNum, func(id int) []shard.Option {

View file

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"math/rand"
"os"
"path/filepath"
"strconv"
"sync"
@ -31,19 +30,14 @@ var providers = []struct {
return f
}},
{"bbolt", func(t testing.TB, opts ...Option) Forest {
// Use `os.TempDir` because we construct multiple times in the same test.
tmpDir, err := os.MkdirTemp(os.TempDir(), "*")
require.NoError(t, err)
f := NewBoltForest(
append([]Option{
WithPath(filepath.Join(tmpDir, "test.db")),
WithPath(filepath.Join(t.TempDir(), "test.db")),
WithMaxBatchSize(1)}, opts...)...)
require.NoError(t, f.Open(false))
require.NoError(t, f.Init())
t.Cleanup(func() {
require.NoError(t, f.Close())
require.NoError(t, os.RemoveAll(tmpDir))
})
return f
}},