From 64660afd2ea50aa0233c936a7f9ede62f82f955b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 17 Aug 2023 15:49:24 +0300 Subject: [PATCH] [#609] Replace zaptest.NewLogger() with zap.L() Semantic patch: ``` @@ @@ -import "go.uber.org/zap/zaptest" +import "go.uber.org/zap" -zaptest.NewLogger(t) +zap.L() ``` Signed-off-by: Evgenii Stratonikov --- .../blobstor/blobovniczatree/exists_test.go | 4 ++-- .../blobstor/blobovniczatree/generic_test.go | 6 +++--- .../blobstor/memstore/memstore_test.go | 4 ++-- pkg/local_object_storage/engine/control_test.go | 3 +-- pkg/local_object_storage/engine/delete_test.go | 4 ++-- pkg/local_object_storage/engine/engine_test.go | 3 +-- pkg/local_object_storage/engine/error_test.go | 4 ++-- pkg/local_object_storage/engine/evacuate_test.go | 4 ++-- pkg/local_object_storage/shard/control_test.go | 4 ++-- pkg/local_object_storage/shard/gc_internal_test.go | 8 ++++---- pkg/local_object_storage/shard/range_test.go | 4 ++-- pkg/local_object_storage/shard/reload_test.go | 4 ++-- pkg/local_object_storage/shard/shard_test.go | 5 ++--- .../writecache/writecachebadger/flush_test.go | 4 ++-- .../writecache/writecachebadger/generic_test.go | 4 ++-- .../writecache/writecachebbolt/flush_test.go | 4 ++-- .../writecache/writecachebbolt/generic_test.go | 4 ++-- pkg/services/tree/signature_test.go | 4 ++-- 18 files changed, 37 insertions(+), 40 deletions(-) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/exists_test.go b/pkg/local_object_storage/blobstor/blobovniczatree/exists_test.go index 8d9fe526e..f9448ae92 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/exists_test.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/exists_test.go @@ -12,13 +12,13 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestExistsInvalidStorageID(t *testing.T) { dir := t.TempDir() b := NewBlobovniczaTree( - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), WithObjectSizeLimit(1024), WithBlobovniczaShallowWidth(2), WithBlobovniczaShallowDepth(2), diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go b/pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go index 7f95e750b..5a713b9b9 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go @@ -6,7 +6,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/internal/blobstortest" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestGeneric(t *testing.T) { @@ -14,7 +14,7 @@ func TestGeneric(t *testing.T) { helper := func(t *testing.T, dir string) common.Storage { return NewBlobovniczaTree( - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), WithObjectSizeLimit(maxObjectSize), WithBlobovniczaShallowWidth(2), WithBlobovniczaShallowDepth(2), @@ -41,7 +41,7 @@ func TestControl(t *testing.T) { newTree := func(t *testing.T) common.Storage { return NewBlobovniczaTree( - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), WithObjectSizeLimit(maxObjectSize), WithBlobovniczaShallowWidth(2), WithBlobovniczaShallowDepth(2), diff --git a/pkg/local_object_storage/blobstor/memstore/memstore_test.go b/pkg/local_object_storage/blobstor/memstore/memstore_test.go index 125276290..7979b1504 100644 --- a/pkg/local_object_storage/blobstor/memstore/memstore_test.go +++ b/pkg/local_object_storage/blobstor/memstore/memstore_test.go @@ -10,13 +10,13 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestSimpleLifecycle(t *testing.T) { s := New( WithRootPath("memstore"), - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), ) t.Cleanup(func() { _ = s.Close() }) require.NoError(t, s.Open(false)) diff --git a/pkg/local_object_storage/engine/control_test.go b/pkg/local_object_storage/engine/control_test.go index 804bef6ec..04591687d 100644 --- a/pkg/local_object_storage/engine/control_test.go +++ b/pkg/local_object_storage/engine/control_test.go @@ -27,7 +27,6 @@ import ( "github.com/stretchr/testify/require" "go.etcd.io/bbolt" "go.uber.org/zap" - "go.uber.org/zap/zaptest" ) // TestInitializationFailure checks that shard is initialized and closed even if media @@ -55,7 +54,7 @@ func TestInitializationFailure(t *testing.T) { return []shard.Option{ shard.WithID(sid), - shard.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + shard.WithLogger(&logger.Logger{Logger: zap.L()}), shard.WithBlobStorOptions( blobstor.WithStorages(storages)), shard.WithMetaBaseOptions( diff --git a/pkg/local_object_storage/engine/delete_test.go b/pkg/local_object_storage/engine/delete_test.go index e4a516512..802b6b0b5 100644 --- a/pkg/local_object_storage/engine/delete_test.go +++ b/pkg/local_object_storage/engine/delete_test.go @@ -13,7 +13,7 @@ import ( oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestDeleteBigObject(t *testing.T) { @@ -54,7 +54,7 @@ func TestDeleteBigObject(t *testing.T) { s3 := testNewShard(t, 3) e := testNewEngine(t).setInitializedShards(t, s1, s2, s3).engine - e.log = &logger.Logger{Logger: zaptest.NewLogger(t)} + e.log = &logger.Logger{Logger: zap.L()} defer e.Close() for i := range children { diff --git a/pkg/local_object_storage/engine/engine_test.go b/pkg/local_object_storage/engine/engine_test.go index e3dd49728..39c5e2e1e 100644 --- a/pkg/local_object_storage/engine/engine_test.go +++ b/pkg/local_object_storage/engine/engine_test.go @@ -23,7 +23,6 @@ import ( "github.com/panjf2000/ants/v2" "github.com/stretchr/testify/require" "go.uber.org/zap" - "go.uber.org/zap/zaptest" ) type epochState struct{} @@ -81,7 +80,7 @@ type testEngineWrapper struct { } func testNewEngine(t testing.TB, opts ...Option) *testEngineWrapper { - engine := New(WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)})) + engine := New(WithLogger(&logger.Logger{Logger: zap.L()})) for _, opt := range opts { opt(engine.cfg) } diff --git a/pkg/local_object_storage/engine/error_test.go b/pkg/local_object_storage/engine/error_test.go index a77149e7c..bbed8cfb9 100644 --- a/pkg/local_object_storage/engine/error_test.go +++ b/pkg/local_object_storage/engine/error_test.go @@ -21,7 +21,7 @@ import ( cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) const errSmallSize = 256 @@ -56,7 +56,7 @@ func newEngineWithErrorThreshold(t testing.TB, dir string, errThreshold uint32) largeFileStorage: largeFileStorage, } return []shard.Option{ - shard.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + shard.WithLogger(&logger.Logger{Logger: zap.L()}), shard.WithBlobStorOptions(blobstor.WithStorages(storages)), shard.WithMetaBaseOptions( meta.WithPath(filepath.Join(dir, fmt.Sprintf("%d.metabase", id))), diff --git a/pkg/local_object_storage/engine/evacuate_test.go b/pkg/local_object_storage/engine/evacuate_test.go index b642ea065..63296ccd7 100644 --- a/pkg/local_object_storage/engine/evacuate_test.go +++ b/pkg/local_object_storage/engine/evacuate_test.go @@ -21,7 +21,7 @@ import ( objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" "golang.org/x/sync/errgroup" ) @@ -31,7 +31,7 @@ func newEngineEvacuate(t *testing.T, shardNum int, objPerShard int) (*StorageEng te := testNewEngine(t). setShardsNumOpts(t, shardNum, func(id int) []shard.Option { return []shard.Option{ - shard.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + shard.WithLogger(&logger.Logger{Logger: zap.L()}), shard.WithBlobStorOptions( blobstor.WithStorages([]blobstor.SubStorage{{ Storage: fstree.New( diff --git a/pkg/local_object_storage/shard/control_test.go b/pkg/local_object_storage/shard/control_test.go index deeb39300..053d89a8a 100644 --- a/pkg/local_object_storage/shard/control_test.go +++ b/pkg/local_object_storage/shard/control_test.go @@ -30,7 +30,7 @@ import ( objecttest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/test" "github.com/stretchr/testify/require" "go.etcd.io/bbolt" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) type epochState struct{} @@ -75,7 +75,7 @@ func TestShardOpen(t *testing.T) { newShard := func() *Shard { return New( WithID(NewIDFromBytes([]byte{})), - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), WithBlobStorOptions( blobstor.WithStorages([]blobstor.SubStorage{ {Storage: st}, diff --git a/pkg/local_object_storage/shard/gc_internal_test.go b/pkg/local_object_storage/shard/gc_internal_test.go index cf6633962..21f300e2c 100644 --- a/pkg/local_object_storage/shard/gc_internal_test.go +++ b/pkg/local_object_storage/shard/gc_internal_test.go @@ -22,7 +22,7 @@ import ( oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "github.com/panjf2000/ants/v2" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) { @@ -32,13 +32,13 @@ func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) { var sh *Shard - l := &logger.Logger{Logger: zaptest.NewLogger(t)} + l := &logger.Logger{Logger: zap.L()} blobOpts := []blobstor.Option{ - blobstor.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + blobstor.WithLogger(&logger.Logger{Logger: zap.L()}), blobstor.WithStorages([]blobstor.SubStorage{ { Storage: blobovniczatree.NewBlobovniczaTree( - blobovniczatree.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + blobovniczatree.WithLogger(&logger.Logger{Logger: zap.L()}), blobovniczatree.WithRootPath(filepath.Join(rootPath, "blob", "blobovnicza")), blobovniczatree.WithBlobovniczaShallowDepth(1), blobovniczatree.WithBlobovniczaShallowWidth(1)), diff --git a/pkg/local_object_storage/shard/range_test.go b/pkg/local_object_storage/shard/range_test.go index 1806990ab..e764a0763 100644 --- a/pkg/local_object_storage/shard/range_test.go +++ b/pkg/local_object_storage/shard/range_test.go @@ -19,7 +19,7 @@ import ( objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestShard_GetRange(t *testing.T) { @@ -82,7 +82,7 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) { []blobstor.Option{blobstor.WithStorages([]blobstor.SubStorage{ { Storage: blobovniczatree.NewBlobovniczaTree( - blobovniczatree.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + blobovniczatree.WithLogger(&logger.Logger{Logger: zap.L()}), blobovniczatree.WithRootPath(filepath.Join(t.TempDir(), "blob", "blobovnicza")), blobovniczatree.WithBlobovniczaShallowDepth(1), blobovniczatree.WithBlobovniczaShallowWidth(1)), diff --git a/pkg/local_object_storage/shard/reload_test.go b/pkg/local_object_storage/shard/reload_test.go index 0b964ba2e..75ce386bc 100644 --- a/pkg/local_object_storage/shard/reload_test.go +++ b/pkg/local_object_storage/shard/reload_test.go @@ -20,7 +20,7 @@ import ( usertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user/test" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestShardReload(t *testing.T) { @@ -29,7 +29,7 @@ func TestShardReload(t *testing.T) { p := t.Name() defer os.RemoveAll(p) - l := &logger.Logger{Logger: zaptest.NewLogger(t)} + l := &logger.Logger{Logger: zap.L()} blobOpts := []blobstor.Option{ blobstor.WithLogger(l), blobstor.WithStorages([]blobstor.SubStorage{ diff --git a/pkg/local_object_storage/shard/shard_test.go b/pkg/local_object_storage/shard/shard_test.go index 3b7c7c4a3..4ec73191c 100644 --- a/pkg/local_object_storage/shard/shard_test.go +++ b/pkg/local_object_storage/shard/shard_test.go @@ -22,7 +22,6 @@ import ( "github.com/panjf2000/ants/v2" "github.com/stretchr/testify/require" "go.uber.org/zap" - "go.uber.org/zap/zaptest" ) type epochState struct { @@ -60,11 +59,11 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts if bsOpts == nil { bsOpts = []blobstor.Option{ - blobstor.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + blobstor.WithLogger(&logger.Logger{Logger: zap.L()}), blobstor.WithStorages([]blobstor.SubStorage{ { Storage: blobovniczatree.NewBlobovniczaTree( - blobovniczatree.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + blobovniczatree.WithLogger(&logger.Logger{Logger: zap.L()}), blobovniczatree.WithRootPath(filepath.Join(rootPath, "blob", "blobovnicza")), blobovniczatree.WithBlobovniczaShallowDepth(1), blobovniczatree.WithBlobovniczaShallowWidth(1)), diff --git a/pkg/local_object_storage/writecache/writecachebadger/flush_test.go b/pkg/local_object_storage/writecache/writecachebadger/flush_test.go index 90e584e02..1bf50e000 100644 --- a/pkg/local_object_storage/writecache/writecachebadger/flush_test.go +++ b/pkg/local_object_storage/writecache/writecachebadger/flush_test.go @@ -14,14 +14,14 @@ import ( oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" "github.com/dgraph-io/badger/v4" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestFlush(t *testing.T) { createCacheFn := func(t *testing.T, smallSize uint64, mb *meta.DB, bs writecache.MainStorage, opts ...Option) writecache.Cache { return New( append([]Option{ - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), WithPath(filepath.Join(t.TempDir(), "writecache")), WithMetabase(mb), WithBlobstor(bs), diff --git a/pkg/local_object_storage/writecache/writecachebadger/generic_test.go b/pkg/local_object_storage/writecache/writecachebadger/generic_test.go index be0a40e00..641da2293 100644 --- a/pkg/local_object_storage/writecache/writecachebadger/generic_test.go +++ b/pkg/local_object_storage/writecache/writecachebadger/generic_test.go @@ -6,13 +6,13 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/storagetest" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestGeneric(t *testing.T) { storagetest.TestAll(t, func(t *testing.T) storagetest.Component { return New( - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), WithFlushWorkersCount(2), WithPath(t.TempDir()), WithGCInterval(1*time.Second)) diff --git a/pkg/local_object_storage/writecache/writecachebbolt/flush_test.go b/pkg/local_object_storage/writecache/writecachebbolt/flush_test.go index acd180130..e7ba66fae 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/flush_test.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/flush_test.go @@ -17,14 +17,14 @@ import ( oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" "github.com/stretchr/testify/require" "go.etcd.io/bbolt" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestFlush(t *testing.T) { createCacheFn := func(t *testing.T, smallSize uint64, mb *meta.DB, bs writecache.MainStorage, opts ...Option) writecache.Cache { return New( append([]Option{ - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), WithPath(filepath.Join(t.TempDir(), "writecache")), WithSmallObjectSize(smallSize), WithMetabase(mb), diff --git a/pkg/local_object_storage/writecache/writecachebbolt/generic_test.go b/pkg/local_object_storage/writecache/writecachebbolt/generic_test.go index 509efdd60..b34d53f3e 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/generic_test.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/generic_test.go @@ -5,13 +5,13 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/storagetest" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) func TestGeneric(t *testing.T) { storagetest.TestAll(t, func(t *testing.T) storagetest.Component { return New( - WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), + WithLogger(&logger.Logger{Logger: zap.L()}), WithFlushWorkersCount(2), WithPath(t.TempDir())) }) diff --git a/pkg/services/tree/signature_test.go b/pkg/services/tree/signature_test.go index eaf9b8b79..482c16157 100644 --- a/pkg/services/tree/signature_test.go +++ b/pkg/services/tree/signature_test.go @@ -20,7 +20,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + "go.uber.org/zap" ) type dummyNetmapSource struct { @@ -97,7 +97,7 @@ func TestMessageSign(t *testing.T) { s := &Service{ cfg: cfg{ - log: &logger.Logger{Logger: zaptest.NewLogger(t)}, + log: &logger.Logger{Logger: zap.L()}, key: &privs[0].PrivateKey, nmSource: dummyNetmapSource{}, cnrSource: dummyContainerSource{ -- 2.45.2