[#668] shard/test: Move tests to the main package

Semantic patch (also, duplicate definitions are removed):
```
@@
var e identifier
@@
-import "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"

-shard.e
+e
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-08-31 15:47:06 +03:00 committed by Evgenii Stratonikov
parent aa23c6a83a
commit bdecfbc1be
12 changed files with 79 additions and 99 deletions

View file

@ -1,4 +1,4 @@
package shard_test
package shard
import (
"context"
@ -11,7 +11,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebadger"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
@ -31,15 +30,15 @@ func (s epochState) CurrentEpoch() uint64 {
return s.Value
}
func newShard(t testing.TB, enableWriteCache bool) *shard.Shard {
func newShard(t testing.TB, enableWriteCache bool) *Shard {
return newCustomShard(t, t.TempDir(), enableWriteCache,
writecacheconfig.Options{Type: writecacheconfig.TypeBBolt},
nil,
nil)
}
func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts writecacheconfig.Options, bsOpts []blobstor.Option, metaOptions []meta.Option) *shard.Shard {
var sh *shard.Shard
func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts writecacheconfig.Options, bsOpts []blobstor.Option, metaOptions []meta.Option) *Shard {
var sh *Shard
if enableWriteCache {
rootPath = filepath.Join(rootPath, "wc")
switch wcOpts.Type {
@ -78,33 +77,33 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts
}
}
opts := []shard.Option{
shard.WithID(shard.NewIDFromBytes([]byte{})),
shard.WithLogger(test.NewLogger(t, true)),
shard.WithBlobStorOptions(bsOpts...),
shard.WithMetaBaseOptions(
opts := []Option{
WithID(NewIDFromBytes([]byte{})),
WithLogger(test.NewLogger(t, true)),
WithBlobStorOptions(bsOpts...),
WithMetaBaseOptions(
append([]meta.Option{
meta.WithPath(filepath.Join(rootPath, "meta")), meta.WithEpochState(epochState{})},
metaOptions...)...,
),
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))),
shard.WithWriteCache(enableWriteCache),
shard.WithWriteCacheOptions(wcOpts),
shard.WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) {
WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))),
WithWriteCache(enableWriteCache),
WithWriteCacheOptions(wcOpts),
WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) {
sh.HandleDeletedLocks(addresses)
}),
shard.WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
sh.HandleExpiredLocks(ctx, epoch, a)
}),
shard.WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
pool, err := ants.NewPool(sz)
require.NoError(t, err)
return pool
}),
shard.WithGCRemoverSleepInterval(100 * time.Millisecond),
WithGCRemoverSleepInterval(100 * time.Millisecond),
}
sh = shard.New(opts...)
sh = New(opts...)
require.NoError(t, sh.Open())
require.NoError(t, sh.Init(context.Background()))
@ -112,6 +111,6 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts
return sh
}
func releaseShard(s *shard.Shard, t testing.TB) {
func releaseShard(s *Shard, t testing.TB) {
require.NoError(t, s.Close())
}