From e3f8470d7a3104082c68524b438a7005fec1232e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 22 Mar 2021 19:44:57 +0300 Subject: [PATCH] [#438] metabase: Write unit tests for checking the absence of payloads Metabase should not store payloads of objects. Set payload in generated test object. Ascertain that objects returned by Get method have no payload. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/metabase/db_test.go | 1 + pkg/local_object_storage/metabase/get_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index d996cbab1..eaaff6de4 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -95,6 +95,7 @@ func generateRawObjectWithCID(t *testing.T, cid *container.ID) *object.RawObject obj.SetVersion(version) obj.SetPayloadChecksum(csum) obj.SetPayloadHomomorphicHash(csumTZ) + obj.SetPayload([]byte{1, 2, 3, 4, 5}) return obj } diff --git a/pkg/local_object_storage/metabase/get_test.go b/pkg/local_object_storage/metabase/get_test.go index e45e06f6b..83947b81d 100644 --- a/pkg/local_object_storage/metabase/get_test.go +++ b/pkg/local_object_storage/metabase/get_test.go @@ -31,7 +31,7 @@ func TestDB_Get(t *testing.T) { newObj, err := meta.Get(db, raw.Object().Address()) require.NoError(t, err) - require.Equal(t, raw.Object(), newObj) + require.Equal(t, raw.CutPayload().Object(), newObj) }) t.Run("put tombstone object", func(t *testing.T) { @@ -43,7 +43,7 @@ func TestDB_Get(t *testing.T) { newObj, err := meta.Get(db, raw.Object().Address()) require.NoError(t, err) - require.Equal(t, raw.Object(), newObj) + require.Equal(t, raw.CutPayload().Object(), newObj) }) t.Run("put storage group object", func(t *testing.T) { @@ -55,7 +55,7 @@ func TestDB_Get(t *testing.T) { newObj, err := meta.Get(db, raw.Object().Address()) require.NoError(t, err) - require.Equal(t, raw.Object(), newObj) + require.Equal(t, raw.CutPayload().Object(), newObj) }) t.Run("put virtual object", func(t *testing.T) { @@ -87,11 +87,11 @@ func TestDB_Get(t *testing.T) { newParent, err := meta.GetRaw(db, parent.Object().Address(), false) require.NoError(t, err) - require.True(t, binaryEqual(parent.Object(), newParent)) + require.True(t, binaryEqual(parent.CutPayload().Object(), newParent)) newChild, err := meta.GetRaw(db, child.Object().Address(), true) require.NoError(t, err) - require.True(t, binaryEqual(child.Object(), newChild)) + require.True(t, binaryEqual(child.CutPayload().Object(), newChild)) }) }