From 4ad04602b224f4e647de8f029c82704e0fcef736 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Mon, 24 Jul 2023 11:18:08 +0400 Subject: [PATCH] slicer: Add slicer tests for all object types Signed-off-by: Evgenii Baidakov --- object/slicer/slicer_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/object/slicer/slicer_test.go b/object/slicer/slicer_test.go index 7ac0d0cc..2c9d83b5 100644 --- a/object/slicer/slicer_test.go +++ b/object/slicer/slicer_test.go @@ -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 @@ -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) @@ -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...) @@ -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...) @@ -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)