Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
62c6d40
functionality working
shubhangi-google Feb 13, 2025
b02f881
adding missing config
shubhangi-google Feb 27, 2025
4a6d3ca
fixing unit tests
shubhangi-google Feb 27, 2025
bb4d94d
fixing lint issues
shubhangi-google Feb 27, 2025
a8a5a36
changing storage_cleint approach
shubhangi-google Mar 10, 2025
7b15578
fix linter
shubhangi-google Mar 10, 2025
238c190
code refactoring
shubhangi-google Mar 13, 2025
756a6ae
wip - implementation 2
shubhangi-google Apr 21, 2025
3dcc3ce
changes working
shubhangi-google Apr 24, 2025
128a8ed
adding test cases
shubhangi-google Apr 30, 2025
c313da6
fix typo
shubhangi-google Apr 30, 2025
9b06029
removing unwanted change
shubhangi-google Apr 30, 2025
77068a5
removing unwanted changes
shubhangi-google Apr 30, 2025
b39dca7
rewritting delete upload
shubhangi-google May 7, 2025
e136db8
Update google-cloud-storage/lib/google/cloud/storage/bucket.rb
shubhangi-google May 21, 2025
2e0294c
chnaging method params
shubhangi-google Jun 11, 2025
86378a6
addressing comments
shubhangi-google Aug 25, 2025
2835d79
removing space
shubhangi-google Aug 25, 2025
d3b9da8
resolving syntax
shubhangi-google Aug 25, 2025
c9c9223
Update bucket.rb
shubhangi-google Aug 25, 2025
61350b0
adding returntype
shubhangi-google Aug 25, 2025
b1331c7
adding returntype
shubhangi-google Aug 25, 2025
7e1a89f
modifying test
shubhangi-google Aug 25, 2025
8d60e4c
fixing rubocop issue in toys
shubhangi-google Aug 26, 2025
c646691
update storage_v1 gem version
shubhangi-google Aug 26, 2025
6f1fb62
updating test cases
shubhangi-google Aug 29, 2025
d4b15a6
updating documentation
shubhangi-google Aug 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .toys/batch-review-legacy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/\.release-please-manifest\.json$/,
/\/CHANGELOG\.md$/,
/\/version\.rb$/,
/\/snippets\/snippet_metadata_[\w\.]+\.json$/,
/\/snippets\/snippet_metadata_[\w.]+\.json$/,
],
},
"releases-wrappers" => {
Expand All @@ -62,7 +62,7 @@
/\.release-please-manifest\.json$/,
/\/CHANGELOG\.md$/,
/\/version\.rb$/,
/\/snippets\/snippet_metadata_[\w\.]+\.json$/,
/\/snippets\/snippet_metadata_[\w.]+\.json$/,
],
},
}.freeze
Expand Down
2 changes: 1 addition & 1 deletion .toys/batch-review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
batch_reviewer.define_preset "releases", based_on: :basic_releases do |preset|
preset.message << :pr_title_number
preset.diff_expectations.expect name: "snippet metadata" do |expect|
expect.change_type(:changed).path_pattern(/\/snippets\/snippet_metadata_[\w\.]+\.json$/)
expect.change_type(:changed).path_pattern(/\/snippets\/snippet_metadata_[\w.]+\.json$/)
end
preset.diff_expectations.expect name: "repo metadata" do |expect|
expect.change_type(:changed).path_pattern(/\/\.repo-metadata\.json$/)
Expand Down
2 changes: 1 addition & 1 deletion google-cloud-storage/google-cloud-storage.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
gem.add_dependency "google-cloud-core", "~> 1.6"
gem.add_dependency "google-apis-core", ">= 0.18", "< 2"
gem.add_dependency "google-apis-iamcredentials_v1", "~> 0.18"
gem.add_dependency "google-apis-storage_v1", ">= 0.42"
gem.add_dependency "google-apis-storage_v1", ">= 0.56"
gem.add_dependency "googleauth", "~> 1.9"
gem.add_dependency "digest-crc", "~> 0.4"
gem.add_dependency "addressable", "~> 2.8"
Expand Down
44 changes: 44 additions & 0 deletions google-cloud-storage/lib/google/cloud/storage/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,30 @@ def default_kms_key= new_default_kms_key
patch_gapi! :encryption
end

##
# Restart resumable upload
# @param [String, ::File] file Path of the file on the filesystem to
# upload. Can be an File object, or File-like object such as StringIO.
# @param [String] upload_id Unique Id of a resumable upload
#
# @return [Google::Apis::StorageV1::Object, Integer]
# The object metadata on success, or 0 request is not completed.
Comment on lines +726 to +727

Choose a reason for hiding this comment

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

medium

The return type documentation appears to be inaccurate. It states that the method can return an Integer (specifically 0) if the request is not completed. However, within this library, an incomplete or failed request typically raises an exception rather than returning a special value. On success, the method should return the Google::Apis::StorageV1::Object. Please update the documentation to reflect this expected behavior.

# @return [Google::Apis::StorageV1::Object]
#   The object metadata on success.

#
# @example
# require "google/cloud/storage"
#
# storage = Google::Cloud::Storage.new
#
# bucket = storage.bucket "my-bucket"
# bucket.restart_resumable_upload file, upload_id

def restart_resumable_upload file, upload_id
ensure_service!
ensure_io_or_file_exists! file
raise ArgumentError, "Upload Id missing" unless upload_id
service.restart_resumable_upload name, file, upload_id
end

##
# The period of time (in seconds) that files in the bucket must be
# retained, and cannot be deleted, overwritten, or archived.
Expand Down Expand Up @@ -1410,6 +1434,26 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil
user_project: user_project
end

##
# Delete resumable upload
# @param [String] upload_id Unique Id of a resumable upload
#
# @return [Boolean,nil] Returns `true` if the resumable upload was deleted, 'nil' if the request is not completed.

Choose a reason for hiding this comment

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

medium

The return type documentation [Boolean,nil] and the explanation are a bit confusing. The mention of nil for an incomplete request is ambiguous, as failed requests typically raise exceptions. For clarity and consistency, it's better for methods that perform a DELETE operation to return true on success. I'll provide a suggestion on the method implementation to align with this.

# @return [Boolean] Returns `true` if the resumable upload was deleted.

#
# @example
# require "google/cloud/storage"
#
# storage = Google::Cloud::Storage.new
#
# bucket = storage.bucket "my-bucket"
# bucket.delete_resumable_upload upload_id

def delete_resumable_upload upload_id
ensure_service!
raise ArgumentError, "Upload Id missing" unless upload_id
service.delete_resumable_upload name, upload_id
end
Comment on lines +1451 to +1455

Choose a reason for hiding this comment

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

medium

To provide a clear success signal to the caller, this method should explicitly return true after the service call completes successfully. The underlying service call for a successful delete might return nil (on an HTTP 204 response), so returning true makes the method's contract more robust and aligns with both the test expectation and the recommended documentation change.

        def delete_resumable_upload upload_id
          ensure_service!
          raise ArgumentError, "Upload Id missing" unless upload_id
          service.delete_resumable_upload name, upload_id
          true
        end


##
# Retrieves a list of files matching the criteria.
#
Expand Down
12 changes: 12 additions & 0 deletions google-cloud-storage/lib/google/cloud/storage/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,18 @@ def delete_file bucket_name,
end
end

def restart_resumable_upload bucket_name, source, upload_id, options: {}
execute do
service.restart_resumable_upload bucket_name, source, upload_id, options: options
end
end

def delete_resumable_upload bucket_name, upload_id, options: {}
execute do
service.delete_resumable_upload bucket_name, upload_id, options: options
end
end

##
# Restore soft deleted bucket
def restore_bucket bucket_name,
Expand Down
78 changes: 78 additions & 0 deletions google-cloud-storage/test/google/cloud/storage/bucket_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,84 @@
end
end

it "restarts a resumable upload with upload_id" do
new_file_name = random_file_path
upload_id = "TEST_ID"

Tempfile.open ["google-cloud", ".txt"] do |tmpfile|
tmpfile.write "Hello world"
tmpfile.rewind
mock = Minitest::Mock.new
expected_return_value = create_file_gapi(bucket.name, new_file_name)
mock.expect :restart_resumable_upload, expected_return_value,
[bucket.name, tmpfile, upload_id],
**resumable_upload_args(options: {})
bucket.service.mocked_service = mock
returned_value= bucket.restart_resumable_upload tmpfile, upload_id
assert_equal expected_return_value, returned_value
mock.verify
end
end

it "raises ArgumentError if anyone or both arguments are not provided to restart_resumable_upload" do
new_file_name = random_file_path

Choose a reason for hiding this comment

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

medium

The variable new_file_name is initialized but never used in this test case. It can be removed to improve code clarity.

upload_id = "TEST_ID"

Tempfile.open ["google-cloud", ".txt"] do |tmpfile|
tmpfile.write "Hello world"
tmpfile.rewind
error = _ { bucket.restart_resumable_upload }.must_raise ArgumentError
assert_match "wrong number of arguments", error.message

error = _ { bucket.restart_resumable_upload upload_id }.must_raise ArgumentError
assert_match "wrong number of arguments", error.message

error = _ { bucket.restart_resumable_upload tmpfile }.must_raise ArgumentError
assert_match "wrong number of arguments", error.message
end
end

it "raises ArgumentError if upload_id as nil is provided to restart_resumable_upload" do
new_file_name = random_file_path

Choose a reason for hiding this comment

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

medium

The variable new_file_name is initialized but never used in this test case. It can be removed.

upload_id = nil

Tempfile.open ["google-cloud", ".txt"] do |tmpfile|
tmpfile.write "Hello world"
tmpfile.rewind
error = _ { bucket.restart_resumable_upload tmpfile, upload_id }.must_raise ArgumentError
assert_match "Upload Id missing", error.message
end
end


it "deletes a resumable upload with upload_id" do
upload_id = "TEST_ID"

mock = Minitest::Mock.new
expected_return_value = true
mock.expect :delete_resumable_upload, expected_return_value,
[bucket.name, upload_id],
**resumable_upload_args(options: {})
bucket.service.mocked_service = mock
returned_value = bucket.delete_resumable_upload upload_id
assert_equal expected_return_value, returned_value
mock.verify
end

it "raises ArgumentError if upload_id is not provided to delete_resumable_upload" do
new_file_name = random_file_path
upload_id = "TEST_ID"
Comment on lines +1476 to +1477

Choose a reason for hiding this comment

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

medium

The variables new_file_name and upload_id are initialized but never used in this test case. They can be removed.

error = _ { bucket.delete_resumable_upload }.must_raise ArgumentError
assert_match "wrong number of arguments", error.message
end

it "raises ArgumentError if upload_id as nil is provided to delete_resumable_upload" do
new_file_name = random_file_path

Choose a reason for hiding this comment

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

medium

The variable new_file_name is initialized but never used in this test case. It can be removed.

upload_id = nil
error = _ { bucket.delete_resumable_upload upload_id }.must_raise ArgumentError
assert_match "Upload Id missing", error.message
end

def create_file_gapi bucket=nil, name = nil
Google::Apis::StorageV1::Object.from_json random_file_hash(bucket, name).to_json
end
Expand Down
6 changes: 6 additions & 0 deletions google-cloud-storage/test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ def insert_object_args name: nil,
}
end

def resumable_upload_args options: {}
{
options: options
}
end

def get_object_args generation: nil,
if_generation_match: nil,
if_generation_not_match: nil,
Expand Down