[#230] shard: Add test for getting SplitInfo
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
bf9e938a3b
commit
7c97bd1360
2 changed files with 59 additions and 1 deletions
|
@ -1,8 +1,12 @@
|
|||
package shard_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -62,4 +66,58 @@ func testShardGet(t *testing.T, sh *shard.Shard) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, obj.Object(), res.Object())
|
||||
})
|
||||
|
||||
t.Run("parent object", func(t *testing.T) {
|
||||
cid := generateCID()
|
||||
splitID := objectSDK.NewSplitID()
|
||||
|
||||
parent := generateRawObjectWithCID(t, cid)
|
||||
addAttribute(parent, "parent", "attribute")
|
||||
|
||||
child := generateRawObjectWithCID(t, cid)
|
||||
child.SetParent(parent.Object().SDK())
|
||||
child.SetParentID(parent.ID())
|
||||
child.SetSplitID(splitID)
|
||||
addPayload(child, 1<<5)
|
||||
|
||||
putPrm.WithObject(child.Object())
|
||||
|
||||
_, err := sh.Put(putPrm)
|
||||
require.NoError(t, err)
|
||||
|
||||
getPrm.WithAddress(child.Object().Address())
|
||||
|
||||
res, err := sh.Get(getPrm)
|
||||
require.NoError(t, err)
|
||||
require.True(t, binaryEqual(child.Object(), res.Object()))
|
||||
|
||||
getPrm.WithAddress(parent.Object().Address())
|
||||
|
||||
_, err = sh.Get(getPrm)
|
||||
|
||||
var expectedErr *objectSDK.SplitInfoError
|
||||
require.True(t, errors.As(err, &expectedErr))
|
||||
|
||||
si, ok := err.(*objectSDK.SplitInfoError)
|
||||
require.True(t, ok)
|
||||
require.Nil(t, si.SplitInfo().Link())
|
||||
require.Equal(t, child.ID(), si.SplitInfo().LastPart())
|
||||
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
||||
})
|
||||
}
|
||||
|
||||
// binary equal is used when object contains empty lists in the structure and
|
||||
// requre.Equal fails on comparing <nil> and []{} lists.
|
||||
func binaryEqual(a, b *object.Object) bool {
|
||||
binaryA, err := a.Marshal()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
binaryB, err := b.Marshal()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return bytes.Equal(binaryA, binaryB)
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ func WithWriteCache(use bool) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// hasWriteCache returns bool if write cache exists on shars.
|
||||
// hasWriteCache returns bool if write cache exists on shards.
|
||||
func (s Shard) hasWriteCache() bool {
|
||||
return s.cfg.useWriteCache
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue