[#xx] Avoid manual management of files in tests

Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
Alejandro Lopez 2023-08-14 14:01:39 +03:00
parent 376f03a445
commit ae8be495c8
13 changed files with 17 additions and 79 deletions

View file

@ -44,18 +44,12 @@ func TestInitializationFailure(t *testing.T) {
sid, err := generateShardID()
require.NoError(t, err)
tempDir := t.TempDir()
blobstorPath := filepath.Join(tempDir, "bs")
metabasePath := filepath.Join(tempDir, "mb")
writecachePath := filepath.Join(tempDir, "wc")
piloramaPath := filepath.Join(tempDir, "pl")
storages, smallFileStorage, largeFileStorage := newTestStorages(blobstorPath, 1<<20)
storages, smallFileStorage, largeFileStorage := newTestStorages(t.TempDir(), 1<<20)
wcOpts := writecacheconfig.Options{
Type: writecacheconfig.TypeBBolt,
BBoltOptions: []writecachebbolt.Option{
writecachebbolt.WithPath(writecachePath),
writecachebbolt.WithPath(t.TempDir()),
},
}
@ -69,13 +63,13 @@ func TestInitializationFailure(t *testing.T) {
Timeout: 100 * time.Millisecond,
OpenFile: opts.openFileMetabase,
}),
meta.WithPath(metabasePath),
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
meta.WithPermissions(0700),
meta.WithEpochState(epochState{})),
shard.WithWriteCache(true),
shard.WithWriteCacheOptions(wcOpts),
shard.WithPiloramaOptions(
pilorama.WithPath(piloramaPath),
pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama")),
pilorama.WithOpenFile(opts.openFilePilorama),
),
}, smallFileStorage, largeFileStorage
@ -178,10 +172,6 @@ func testEngineFailInitAndReload(t *testing.T, errOnAdd bool, opts []shard.Optio
func TestExecBlocks(t *testing.T) {
e := testNewEngine(t).setShardsNum(t, 2).engine // number doesn't matter in this test, 2 is several but not many
t.Cleanup(func() {
os.RemoveAll(t.Name())
})
// put some object
obj := testutil.GenerateObjectWithCID(cidtest.ID())

View file

@ -2,7 +2,6 @@ package engine
import (
"context"
"os"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
@ -20,8 +19,6 @@ import (
func TestDeleteBigObject(t *testing.T) {
t.Parallel()
defer os.RemoveAll(t.Name())
cnr := cidtest.ID()
parentID := oidtest.ID()
splitID := objectSDK.NewSplitID()

View file

@ -2,7 +2,6 @@ package engine
import (
"context"
"fmt"
"os"
"path/filepath"
"sync/atomic"
@ -204,11 +203,10 @@ func testDefaultShardOptions(t testing.TB, id int) []shard.Option {
shard.WithLogger(&logger.Logger{Logger: zap.L()}),
shard.WithBlobStorOptions(
blobstor.WithStorages(
newStorages(filepath.Join(t.Name(), fmt.Sprintf("%d.blobstor", id)),
1<<20))),
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.Name(), fmt.Sprintf("%d.pilorama", id)))),
newStorages(t.TempDir(), 1<<20))),
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama"))),
shard.WithMetaBaseOptions(
meta.WithPath(filepath.Join(t.Name(), fmt.Sprintf("%d.metabase", id))),
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
meta.WithPermissions(0700),
meta.WithEpochState(epochState{}),
)}

View file

@ -2,7 +2,6 @@ package engine
import (
"context"
"os"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
@ -14,8 +13,6 @@ import (
)
func TestHeadRaw(t *testing.T) {
defer os.RemoveAll(t.Name())
cnr := cidtest.ID()
splitID := objectSDK.NewSplitID()

View file

@ -2,7 +2,6 @@ package engine
import (
"context"
"os"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
@ -14,8 +13,6 @@ import (
)
func TestStorageEngine_Inhume(t *testing.T) {
defer os.RemoveAll(t.Name())
cnr := cidtest.ID()
splitID := objectSDK.NewSplitID()

View file

@ -2,8 +2,6 @@ package engine
import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
"testing"
@ -71,11 +69,10 @@ func TestListWithCursor(t *testing.T) {
shard.WithLogger(&logger.Logger{Logger: zap.L()}),
shard.WithBlobStorOptions(
blobstor.WithStorages(
newStorages(filepath.Join(t.Name(), tt.name, fmt.Sprintf("%d.blobstor", id)),
1<<20))),
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.Name(), tt.name, fmt.Sprintf("%d.pilorama", id)))),
newStorages(t.TempDir(), 1<<20))),
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama"))),
shard.WithMetaBaseOptions(
meta.WithPath(filepath.Join(t.Name(), tt.name, fmt.Sprintf("%d.metabase", id))),
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
meta.WithPermissions(0700),
meta.WithEpochState(epochState{}),
)}
@ -85,7 +82,6 @@ func TestListWithCursor(t *testing.T) {
t.Cleanup(func() {
e.Close()
os.RemoveAll(t.Name())
})
expected := make([]object.AddressWithType, 0, tt.objectNum)

View file

@ -2,7 +2,6 @@ package engine
import (
"context"
"os"
"strconv"
"testing"
"time"
@ -65,7 +64,6 @@ func TestLockUserScenario(t *testing.T) {
t.Cleanup(func() {
_ = e.Close()
_ = os.RemoveAll(t.Name())
})
lockerID := oidtest.ID()
@ -174,7 +172,6 @@ func TestLockExpiration(t *testing.T) {
t.Cleanup(func() {
_ = e.Close()
_ = os.RemoveAll(t.Name())
})
const lockerExpiresAfter = 13
@ -254,7 +251,6 @@ func TestLockForceRemoval(t *testing.T) {
require.NoError(t, e.Init(context.Background()))
t.Cleanup(func() {
_ = e.Close()
_ = os.RemoveAll(t.Name())
})
cnr := cidtest.ID()

View file

@ -1,7 +1,6 @@
package engine
import (
"os"
"testing"
"github.com/stretchr/testify/require"
@ -14,7 +13,6 @@ func TestRemoveShard(t *testing.T) {
e, ids := te.engine, te.shardIDs
t.Cleanup(func() {
e.Close()
os.RemoveAll(t.Name())
})
require.Equal(t, numOfShards, len(e.shardPools))