From 9f019c7470269f0b608bce991dc3faccde8d1a41 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 5 Jul 2022 11:04:21 +0300 Subject: [PATCH] [#542] Add test to check delete marker Signed-off-by: Denis Kirillov --- api/handler/delete_test.go | 20 +++++++++++++++++++- api/layer/layer.go | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/api/handler/delete_test.go b/api/handler/delete_test.go index 1e3ae2b63..a1b75d67c 100644 --- a/api/handler/delete_test.go +++ b/api/handler/delete_test.go @@ -73,7 +73,7 @@ func TestRemoveDeleteMarker(t *testing.T) { checkFound(t, tc, bktName, objName, objInfo.Version()) deleteObject(t, tc, bktName, objName, deleteMarkerVersion) - checkNotFound(t, tc, bktName, objName, emptyVersion) + checkFound(t, tc, bktName, objName, emptyVersion) require.True(t, existInMockedNeoFS(tc, bktInfo, objInfo), "object doesn't exist but should") } @@ -154,6 +154,24 @@ func TestDeleteObjectFromListCache(t *testing.T) { require.False(t, existInMockedNeoFS(tc, bktInfo, objInfo)) } +func TestDeleteObjectCheckMarkerReturn(t *testing.T) { + tc := prepareHandlerContext(t) + + bktName, objName := "bucket-for-removal", "object-to-delete" + createVersionedBucketAndObject(t, tc, bktName, objName) + + deleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion) + + versions := listVersions(t, tc, bktName) + require.Len(t, versions.DeleteMarker, 1) + require.Equal(t, deleteMarker, versions.DeleteMarker[0].VersionID) + + deleteMarker2 := deleteObject(t, tc, bktName, objName, deleteMarker) + versions = listVersions(t, tc, bktName) + require.Len(t, versions.DeleteMarker, 0) + require.Equal(t, deleteMarker, deleteMarker2) +} + func createBucketAndObject(t *testing.T, tc *handlerContext, bktName, objName string) (*data.BucketInfo, *data.ObjectInfo) { createTestBucket(tc.Context(), t, tc, bktName) bktInfo, err := tc.Layer().GetBucketInfo(tc.Context(), bktName) diff --git a/api/layer/layer.go b/api/layer/layer.go index bf73c8431..d6eb70ac9 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -514,6 +514,9 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings obj.Error = fmt.Errorf("couldn't get random oid: %w", err) return obj } + + obj.DeleteMarkVersion = randOID.EncodeToString() + newVersion = &data.NodeVersion{ BaseNodeVersion: data.BaseNodeVersion{ OID: randOID,