-
Notifications
You must be signed in to change notification settings - Fork 570
feat(storage): support delete source objects on compose #34665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -429,6 +429,52 @@ def mock_cipher.random_key | |
| end | ||
|
|
||
| refute_nil bucket.file remote_file_name | ||
| refute_nil bucket.file file_1_name | ||
| refute_nil bucket.file file_2_name | ||
| end | ||
|
|
||
| it "compose_file with delete_source_objects" do | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: For resiliency against edge cases, it would be awesome to add a test to cover how the client behaves if a compose operation fails midway (ex. due to a transient API error). Otherwise LGTM!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done Co-authored by AI Agent |
||
| file_1 = bucket.create_file local_file, file_1_name | ||
| file_2 = bucket.create_file local_file, file_2_name | ||
|
|
||
| expected_out = "Composed new file #{remote_file_name} in the bucket #{bucket.name} " \ | ||
| "by combining #{file_1.name} and #{file_2.name}\n" \ | ||
| "Source objects were deleted\n" | ||
| assert_output expected_out do | ||
| compose_file bucket_name: bucket.name, | ||
| first_file_name: file_1.name, | ||
| second_file_name: file_2.name, | ||
| destination_file_name: remote_file_name, | ||
| delete_source_objects: true | ||
| end | ||
|
|
||
| refute_nil bucket.file remote_file_name | ||
| assert_nil bucket.file file_1_name | ||
| assert_nil bucket.file file_2_name | ||
| end | ||
|
|
||
| it "compose_file with delete_source_objects failing does not delete source objects" do | ||
| file_1 = bucket.create_file local_file, file_1_name | ||
| file_2 = bucket.create_file local_file, file_2_name | ||
|
|
||
| real_storage = Google::Cloud::Storage.new | ||
| bucket.stub :compose, ->(*) { raise Google::Cloud::Error, "Mock API error" } do | ||
| real_storage.stub :bucket, bucket do | ||
| Google::Cloud::Storage.stub :new, real_storage do | ||
| assert_raises Google::Cloud::Error do | ||
| compose_file bucket_name: bucket.name, | ||
| first_file_name: file_1.name, | ||
| second_file_name: file_2.name, | ||
| destination_file_name: remote_file_name, | ||
| delete_source_objects: true | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| refute_nil bucket.file file_1_name | ||
| refute_nil bucket.file file_2_name | ||
| assert_nil bucket.file remote_file_name | ||
| end | ||
|
|
||
| it "copy_file" do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: What do you think about asserting that the source files remain intact in this default test block above? I looked at the previous PR that adds in the
delete_source_objectsparam and I'm wondering if we can add an extra check to validate thedelete_source_objects: falsevalue doesn't accidentally delete the source files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Co-authored by AI Agent