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 26, 2023
1 parent 2f4fbfb commit f87b699
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 @@ -189,6 +189,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 @@ -261,9 +262,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 @@ -276,7 +288,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 @@ -323,7 +335,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 @@ -579,6 +591,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 f87b699

Please sign in to comment.