Skip to content

Conversation

@mahendra-google
Copy link
Owner

@mahendra-google mahendra-google commented Apr 30, 2025

Add samples and test cases for soft delete objects as follows:-

  • storage_list_soft_deleted_objects
  • storage_list_soft_deleted_object_versions
  • storage_restore_object

@mahendra-google mahendra-google self-assigned this Apr 30, 2025
@mahendra-google mahendra-google changed the title samples(storage) add samples and test cases for soft delete objects samples(storage): add samples and test cases for soft delete objects May 2, 2025
Copy link
Collaborator

@amrik-mahal amrik-mahal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@mahendra-google
Copy link
Owner Author

/Gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds new samples and corresponding tests for Google Cloud Storage soft-delete features: listing soft-deleted objects, listing soft-deleted versions of an object, and restoring a soft-deleted object. The new samples and helper methods in StorageFixture are well-implemented. However, I've found critical issues in the test setup for all three new test classes. The tests create buckets without enabling the soft-delete feature (and in one case, without versioning), which is necessary for the features under test to work as expected. I've provided suggestions to correct the bucket creation in each test file.

ListSoftDeletedObjectsSample listSoftDeletedObjects = new ListSoftDeletedObjectsSample();
UploadObjectFromMemorySample uploadObjectFromMemory = new UploadObjectFromMemorySample();
var bucketName = _fixture.GenerateBucketName();
_fixture.CreateBucket(bucketName, multiVersion: false, softDelete: false, registerForDeletion: true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The test is for listing soft-deleted objects, but the bucket is created with soft-delete disabled (softDelete: false). To ensure the test correctly validates the soft-delete functionality, you should enable it when creating the bucket.

_fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true, registerForDeletion: true);

RestoreSoftDeletedObjectSample restoreSoftDeletedObjectSample = new RestoreSoftDeletedObjectSample();
GetMetadataSample getMetadataSample = new GetMetadataSample();
var bucketName = _fixture.GenerateBucketName();
_fixture.CreateBucket(bucketName, multiVersion: false, softDelete: false, registerForDeletion: true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test is for listing soft-deleted versions of an object. For this to work correctly, both versioning and soft-delete must be enabled on the bucket. Currently, both are disabled in the bucket creation step (multiVersion: false, softDelete: false).

_fixture.CreateBucket(bucketName, multiVersion: true, softDelete: true, registerForDeletion: true);

UploadObjectFromMemorySample uploadObjectFromMemory = new UploadObjectFromMemorySample();
GetMetadataSample getMetadataSample = new GetMetadataSample();
var bucketName = _fixture.GenerateBucketName();
_fixture.CreateBucket(bucketName, multiVersion: false, softDelete: false, registerForDeletion: true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To test restoring a soft-deleted object, the bucket must have soft-delete enabled. The bucket is currently created with softDelete: false. Please enable it to ensure the test is valid.

_fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true, registerForDeletion: true);

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist I think soft delete object and bucket are a different

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that soft-delete applies to objects, but the ability to soft-delete objects is a bucket-level configuration. If a bucket does not have soft-delete enabled, then deleting an object within that bucket will result in a permanent deletion, not a soft-delete.

For the RestoreSoftDeletedObjectTest to effectively test the restoration of a soft-deleted object, the bucket used in the test must first be configured to support soft-deletion. This ensures that when an object is 'deleted' in the test, it is indeed soft-deleted and thus available for restoration. The current softDelete: false setting would lead to permanent deletion, making the restoration step impossible to test correctly.

Therefore, the suggestion to set softDelete: true is crucial for the test's validity.

Suggested change
_fixture.CreateBucket(bucketName, multiVersion: false, softDelete: false, registerForDeletion: true);
_fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true, registerForDeletion: true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants