From 93a0ca2d40f6b96ce0cbd9a27a1a5cac6f89ed22 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 bed18400..c53b7bed 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)