From 78bf17c0b0cab2d84b67273441a37cb16cf9e3b5 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 23 Aug 2022 16:07:24 +0300 Subject: [PATCH] [#1686] blobstor/*: Remove unneeded tests The blobovniczatree test also checks the amount of objects we can put, so leave it here. Signed-off-by: Evgenii Stratonikov --- .../blobovniczatree/blobovnicza_test.go | 83 +-------- .../blobstor/fstree/fstree_test.go | 157 ------------------ 2 files changed, 3 insertions(+), 237 deletions(-) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go index b1febdba5..e5d0dde1a 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go @@ -7,32 +7,12 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/internal/blobstortest" "github.com/nspcc-dev/neofs-node/pkg/util/logger/test" - apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" - objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" - oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) -func testObject(sz uint64) *objectSDK.Object { - raw := objectSDK.New() - - raw.SetID(oidtest.ID()) - raw.SetContainerID(cidtest.ID()) - - raw.SetPayload(make([]byte, sz)) - - // fit the binary size to the required - data, _ := raw.Marshal() - if ln := uint64(len(data)); ln > sz { - raw.SetPayload(raw.Payload()[:sz-(ln-sz)]) - } - - return raw -} - func TestBlobovniczas(t *testing.T) { rand.Seed(1024) @@ -64,7 +44,7 @@ func TestBlobovniczas(t *testing.T) { minFitObjNum := width * depth * szLim / objSz for i := uint64(0); i < minFitObjNum; i++ { - obj := testObject(objSz) + obj := blobstortest.NewObject(objSz) addr := object.AddressOf(obj) addrList = append(addrList, addr) @@ -73,64 +53,7 @@ func TestBlobovniczas(t *testing.T) { require.NoError(t, err) // save object in blobovnicza - pRes, err := b.Put(common.PutPrm{Address: addr, RawData: d}) + _, err = b.Put(common.PutPrm{Address: addr, RawData: d}) require.NoError(t, err, i) - - // get w/ blobovnicza ID - var prm common.GetPrm - prm.StorageID = pRes.StorageID - prm.Address = addr - - res, err := b.Get(prm) - require.NoError(t, err) - require.Equal(t, obj, res.Object) - - // get w/o blobovnicza ID - prm.StorageID = nil - - res, err = b.Get(prm) - require.NoError(t, err) - require.Equal(t, obj, res.Object) - - // get range w/ blobovnicza ID - var rngPrm common.GetRangePrm - rngPrm.StorageID = pRes.StorageID - rngPrm.Address = addr - - payload := obj.Payload() - pSize := uint64(len(obj.Payload())) - - off, ln := pSize/3, 2*pSize/3 - rngPrm.Range.SetOffset(off) - rngPrm.Range.SetLength(ln) - - rngRes, err := b.GetRange(rngPrm) - require.NoError(t, err) - require.Equal(t, payload[off:off+ln], rngRes.Data) - - // get range w/o blobovnicza ID - rngPrm.StorageID = nil - - rngRes, err = b.GetRange(rngPrm) - require.NoError(t, err) - require.Equal(t, payload[off:off+ln], rngRes.Data) - } - - var dPrm common.DeletePrm - var gPrm common.GetPrm - - for i := range addrList { - dPrm.Address = addrList[i] - - _, err := b.Delete(dPrm) - require.NoError(t, err) - - gPrm.Address = addrList[i] - - _, err = b.Get(gPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) - - _, err = b.Delete(dPrm) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) } } diff --git a/pkg/local_object_storage/blobstor/fstree/fstree_test.go b/pkg/local_object_storage/blobstor/fstree/fstree_test.go index 1c7103d7c..6a5b9f1a6 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree_test.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree_test.go @@ -1,16 +1,9 @@ package fstree import ( - "errors" - "os" - "path/filepath" "testing" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" - "github.com/nspcc-dev/neofs-node/pkg/util" - oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test" "github.com/stretchr/testify/require" ) @@ -21,153 +14,3 @@ func TestAddressToString(t *testing.T) { require.NoError(t, err) require.Equal(t, addr, *actual) } - -func TestFSTree(t *testing.T) { - tmpDir := filepath.Join(os.TempDir(), "neofs.fstree.test") - require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) - t.Cleanup(func() { require.NoError(t, os.RemoveAll(tmpDir)) }) - - fs := FSTree{ - Info: Info{ - Permissions: os.ModePerm, - RootPath: tmpDir, - }, - Depth: 2, - DirNameLen: 2, - } - - const count = 3 - var addrs []oid.Address - - store := map[string][]byte{} - - for i := 0; i < count; i++ { - a := oidtest.Address() - addrs = append(addrs, a) - - data, err := objecttest.Object().Marshal() - require.NoError(t, err) - - _, err = fs.Put(common.PutPrm{Address: a, RawData: data}) - require.NoError(t, err) - store[a.EncodeToString()] = data - } - - t.Run("get", func(t *testing.T) { - for _, a := range addrs { - actual, err := fs.Get(common.GetPrm{Address: a}) - require.NoError(t, err) - require.Equal(t, store[a.EncodeToString()], actual.RawData) - } - - _, err := fs.Get(common.GetPrm{Address: oidtest.Address()}) - require.Error(t, err) - }) - - t.Run("exists", func(t *testing.T) { - for _, a := range addrs { - res, err := fs.Exists(common.ExistsPrm{Address: a}) - require.NoError(t, err) - require.True(t, res.Exists) - } - - res, err := fs.Exists(common.ExistsPrm{Address: oidtest.Address()}) - require.NoError(t, err) - require.False(t, res.Exists) - }) - - t.Run("iterate", func(t *testing.T) { - n := 0 - var iterationPrm common.IteratePrm - iterationPrm.Handler = func(elem common.IterationElement) error { - n++ - addr := elem.Address.EncodeToString() - expected, ok := store[addr] - require.True(t, ok, "object %s was not found", addr) - require.Equal(t, elem.ObjectData, expected) - return nil - } - - _, err := fs.Iterate(iterationPrm) - - require.NoError(t, err) - require.Equal(t, count, n) - - t.Run("leave early", func(t *testing.T) { - n := 0 - errStop := errors.New("stop") - - iterationPrm.Handler = func(_ common.IterationElement) error { - if n++; n == count-1 { - return errStop - } - return nil - } - - _, err := fs.Iterate(iterationPrm) - - require.ErrorIs(t, err, errStop) - require.Equal(t, count-1, n) - }) - - t.Run("ignore errors", func(t *testing.T) { - n := 0 - - // Unreadable directory. - require.NoError(t, os.Mkdir(filepath.Join(fs.RootPath, "ZZ"), 0)) - - // Unreadable file. - p := fs.treePath(oidtest.Address()) - require.NoError(t, util.MkdirAllX(filepath.Dir(p), fs.Permissions)) - require.NoError(t, os.WriteFile(p, []byte{1, 2, 3}, 0)) - - // Invalid address. - p = fs.treePath(oidtest.Address()) + ".invalid" - require.NoError(t, util.MkdirAllX(filepath.Dir(p), fs.Permissions)) - require.NoError(t, os.WriteFile(p, []byte{1, 2, 3}, fs.Permissions)) - - iterationPrm.IgnoreErrors = true - iterationPrm.Handler = func(_ common.IterationElement) error { - n++ - return nil - } - - _, err := fs.Iterate(iterationPrm) - require.NoError(t, err) - require.Equal(t, count, n) - - t.Run("error from handler is returned", func(t *testing.T) { - expectedErr := errors.New("expected error") - n := 0 - - iterationPrm.Handler = func(_ common.IterationElement) error { - n++ - if n == count/2 { // process some iterations - return expectedErr - } - return nil - } - - _, err := fs.Iterate(iterationPrm) - require.ErrorIs(t, err, expectedErr) - require.Equal(t, count/2, n) - }) - }) - }) - - t.Run("delete", func(t *testing.T) { - _, err := fs.Delete(common.DeletePrm{Address: addrs[0]}) - require.NoError(t, err) - - res, err := fs.Exists(common.ExistsPrm{Address: addrs[0]}) - require.NoError(t, err) - require.False(t, res.Exists) - - res, err = fs.Exists(common.ExistsPrm{Address: addrs[1]}) - require.NoError(t, err) - require.True(t, res.Exists) - - _, err = fs.Delete(common.DeletePrm{Address: oidtest.Address()}) - require.Error(t, err) - }) -}