Skip to content

Commit

Permalink
slicer: Add slicer tests for all object types
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Jul 24, 2023
1 parent a28d4f7 commit af3ae26
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions object/slicer/slicer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ type input struct {
signer neofscrypto.Signer
container cid.ID
owner user.ID
objectType object.Type
currentEpoch uint64
payloadLimit uint64
sessionToken *session.Object
Expand Down Expand Up @@ -259,9 +260,20 @@ func testSlicer(t *testing.T, size, sizeLimit uint64) {
chainCollector: newChainCollector(t),
}

for i := object.TypeRegular; i <= object.TypeLock; i++ {
in.objectType = i

t.Run("slicer with "+i.EncodeToString(), func(t *testing.T) {
testSlicerByHeaderType(t, checker, in, opts)
})
}
}

func testSlicerByHeaderType(t *testing.T, checker *slicedObjectChecker, in input, opts slicer.Options) {
ctx := context.Background()

t.Run("Slicer.Put", func(t *testing.T) {
checker.chainCollector = newChainCollector(t)
s, err := slicer.New(ctx, checker, checker.input.signer, checker.input.container, checker.input.owner, checker.input.sessionToken)
require.NoError(t, err)

Expand All @@ -274,7 +286,7 @@ func testSlicer(t *testing.T, size, sizeLimit uint64) {
checker.chainCollector = newChainCollector(t)

var hdr object.Object
opts.Session()
hdr.SetSessionToken(opts.Session())
hdr.SetContainerID(in.container)
hdr.SetOwnerID(&in.owner)
hdr.SetAttributes(in.attributes...)
Expand Down Expand Up @@ -321,7 +333,7 @@ func testSlicer(t *testing.T, size, sizeLimit uint64) {
checker.chainCollector = newChainCollector(t)

var hdr object.Object
opts.Session()
hdr.SetSessionToken(opts.Session())
hdr.SetContainerID(in.container)
hdr.SetOwnerID(&in.owner)
hdr.SetAttributes(in.attributes...)
Expand Down Expand Up @@ -577,6 +589,8 @@ func (x *chainCollector) verify(in input, rootID oid.ID) {
restoredChain := []oid.ID{x.first}
restoredPayload := bytes.NewBuffer(make([]byte, 0, rootObj.PayloadSize()))

require.Equal(x.tb, in.objectType, rootObj.Type())

for {
v, ok := x.mPayloads[restoredChain[len(restoredChain)-1]]
require.True(x.tb, ok)
Expand Down

0 comments on commit af3ae26

Please sign in to comment.