-
Notifications
You must be signed in to change notification settings - Fork 0
Restart delete resumable upload v4 test1 #38
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
62c6d40
b02f881
4a6d3ca
bb4d94d
a8a5a36
7b15578
238c190
756a6ae
3dcc3ce
128a8ed
c313da6
9b06029
77068a5
b39dca7
e136db8
2e0294c
86378a6
2835d79
d3b9da8
c9c9223
61350b0
b1331c7
7e1a89f
8d60e4c
c646691
6f1fb62
d4b15a6
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 |
|---|---|---|
|
|
@@ -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. | ||
| # | ||
| # @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. | ||
|
|
@@ -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. | ||
|
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. The return type documentation # @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
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. To provide a clear success signal to the caller, this method should explicitly return 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. | ||
| # | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
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. |
||
| 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 | ||
|
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. |
||
| 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
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. |
||
| 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 | ||
|
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. |
||
| 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 | ||
|
|
||
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.
The return type documentation appears to be inaccurate. It states that the method can return an
Integer(specifically0) 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 theGoogle::Apis::StorageV1::Object. Please update the documentation to reflect this expected behavior.