[#668] shard/test: Use sane defaults in the test constructor

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-09-06 17:48:00 +03:00 committed by Evgenii Stratonikov
parent 268adb79cb
commit c661ba1312
3 changed files with 11 additions and 15 deletions

View file

@ -10,7 +10,6 @@ import (
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
@ -26,10 +25,7 @@ func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) {
Value: 100, Value: 100,
} }
wcOpts := writecacheconfig.Options{ sh := newCustomShard(t, false, shardOptions{metaOptions: []meta.Option{meta.WithEpochState(epoch)}})
Type: writecacheconfig.TypeBBolt,
}
sh := newCustomShard(t, false, shardOptions{rootPath: t.TempDir(), wcOpts: wcOpts, metaOptions: []meta.Option{meta.WithEpochState(epoch)}})
t.Cleanup(func() { t.Cleanup(func() {
releaseShard(sh, t) releaseShard(sh, t)
@ -126,10 +122,7 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) {
linkID, _ := link.ID() linkID, _ := link.ID()
wcOpts := writecacheconfig.Options{ sh := newCustomShard(t, false, shardOptions{metaOptions: []meta.Option{meta.WithEpochState(epoch)}})
Type: writecacheconfig.TypeBBolt,
}
sh := newCustomShard(t, false, shardOptions{rootPath: t.TempDir(), wcOpts: wcOpts, metaOptions: []meta.Option{meta.WithEpochState(epoch)}})
t.Cleanup(func() { t.Cleanup(func() {
releaseShard(sh, t) releaseShard(sh, t)

View file

@ -77,7 +77,6 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) {
} }
sh := newCustomShard(t, hasWriteCache, shardOptions{ sh := newCustomShard(t, hasWriteCache, shardOptions{
rootPath: t.TempDir(),
wcOpts: wcOpts, wcOpts: wcOpts,
bsOpts: []blobstor.Option{ bsOpts: []blobstor.Option{
blobstor.WithStorages([]blobstor.SubStorage{ blobstor.WithStorages([]blobstor.SubStorage{

View file

@ -38,15 +38,19 @@ type shardOptions struct {
} }
func newShard(t testing.TB, enableWriteCache bool) *Shard { func newShard(t testing.TB, enableWriteCache bool) *Shard {
sh := newCustomShard(t, enableWriteCache, shardOptions{ sh := newCustomShard(t, enableWriteCache, shardOptions{})
rootPath: t.TempDir(),
wcOpts: writecacheconfig.Options{Type: writecacheconfig.TypeBBolt},
})
t.Cleanup(func() { releaseShard(sh, t) }) t.Cleanup(func() { releaseShard(sh, t) })
return sh return sh
} }
func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard { func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard {
if o.rootPath == "" {
o.rootPath = t.TempDir()
}
if enableWriteCache && o.wcOpts.Type == 0 {
o.wcOpts.Type = writecacheconfig.TypeBBolt
}
var sh *Shard var sh *Shard
if enableWriteCache { if enableWriteCache {
o.rootPath = filepath.Join(o.rootPath, "wc") o.rootPath = filepath.Join(o.rootPath, "wc")