feat(storage): update compose sample to support deleteSourceObjects option#14323
feat(storage): update compose sample to support deleteSourceObjects option#14323nidhiii-27 wants to merge 3 commits into
Conversation
…ption Update compose_file snippet to support delete_source_objects option. Add corresponding system integration tests. [Generated-by: AI]
There was a problem hiding this comment.
Code Review
This pull request adds an optional delete_source_objects parameter to the compose_file function, enabling automatic deletion of source blobs after composition. It also updates the test suite to verify this behavior. The review feedback suggests updating the function's docstring to document this new parameter and simplifying the test by replacing an unnecessary local temporary file with a unique string.
| destination_blob_name, | ||
| delete_source_objects=False, | ||
| ): | ||
| """Concatenate source blobs into destination blob.""" |
There was a problem hiding this comment.
| with tempfile.NamedTemporaryFile() as dest_file: | ||
| destination = storage_compose_file.compose_file( | ||
| test_bucket.name, | ||
| source_files[0], | ||
| source_files[1], | ||
| dest_file.name, | ||
| delete_source_objects=True, | ||
| ) | ||
| composed = destination.download_as_bytes() | ||
| assert composed.decode("utf-8") == source_files[0] + source_files[1] |
There was a problem hiding this comment.
Using tempfile.NamedTemporaryFile is unnecessary here because compose_file only interacts with GCS blobs and does not read from or write to the local filesystem. We can simplify this by using a unique string for the destination blob name, avoiding the overhead of creating and deleting a temporary file on disk.
dest_blob_name = f"test_compose_dest_{uuid.uuid4().hex}"
destination = storage_compose_file.compose_file(
test_bucket.name,
source_files[0],
source_files[1],
dest_blob_name,
delete_source_objects=True,
)
composed = destination.download_as_bytes()
assert composed.decode("utf-8") == source_files[0] + source_files[1]
Update compose_file snippet to support delete_source_objects option.
Add corresponding system integration tests.
[Generated-by: AI]