-
Notifications
You must be signed in to change notification settings - Fork 0
Setting default checksum new1 #50
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
5c57b8f
7c7a46b
f0c499f
d6af83e
7563dfd
ba3a630
fb0ac51
ea292dd
e8d120d
ce60e6d
8b94669
7077e2e
79f420d
c6558be
090b64c
506d92d
e66fdb0
7212ef1
45d8616
2a4f36f
8b803fc
62387c1
84496d9
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 |
|---|---|---|
|
|
@@ -101,6 +101,41 @@ | |
| _(bucket_complete.autoclass_enabled).must_equal bucket_autoclass_enabled | ||
| _(bucket_complete.autoclass_terminal_storage_class).must_equal bucket_autoclass_terminal_storage_class | ||
| end | ||
|
|
||
| it "creates a file with checksum: :crc32c by default" do | ||
| new_file_name = random_file_path | ||
|
|
||
| Tempfile.open ["google-cloud", ".txt"] do |tmpfile| | ||
| tmpfile.write "Hello world!" | ||
| tmpfile.rewind | ||
|
|
||
| crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile | ||
|
|
||
| mock = Minitest::Mock.new | ||
| mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), | ||
| [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) | ||
|
|
||
| bucket.service.mocked_service = mock | ||
| bucket.create_file tmpfile, new_file_name | ||
|
|
||
| mock.verify | ||
| end | ||
| end | ||
|
|
||
| it "creates a file with a StringIO and checksum: :crc32c by default" do | ||
| new_file_name = random_file_path | ||
| new_file_contents = StringIO.new "Hello world" | ||
| crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for new_file_contents | ||
| mock = Minitest::Mock.new | ||
| mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), | ||
| [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) | ||
|
|
||
| bucket.service.mocked_service = mock | ||
|
|
||
| bucket.create_file new_file_contents, new_file_name | ||
|
|
||
| mock.verify | ||
| end | ||
|
|
||
| it "returns frozen cors" do | ||
| bucket_complete.cors.each do |cors| | ||
|
|
@@ -405,6 +440,42 @@ | |
| end | ||
| end | ||
|
|
||
| it "creates a file with no checksum" do | ||
| new_file_name = random_file_path | ||
|
|
||
| Tempfile.open ["google-cloud", ".txt"] do |tmpfile| | ||
| tmpfile.write "Hello world!" | ||
| tmpfile.rewind | ||
|
|
||
| mock = Minitest::Mock.new | ||
| mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), | ||
| [bucket.name, empty_file_gapi(checksum: false)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) | ||
|
|
||
| bucket.service.mocked_service = mock | ||
|
|
||
| bucket.create_file tmpfile, new_file_name, checksum: false | ||
| mock.verify | ||
| end | ||
| end | ||
|
|
||
| it "creates a file with crc32c if checksum is true" do | ||
| new_file_name = random_file_path | ||
|
|
||
| Tempfile.open ["google-cloud", ".txt"] do |tmpfile| | ||
| tmpfile.write "Hello world!" | ||
| tmpfile.rewind | ||
|
|
||
| mock = Minitest::Mock.new | ||
| mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), | ||
| [bucket.name, empty_file_gapi(checksum: true, crc32c: "e5jnUQ==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) | ||
| bucket.service.mocked_service = mock | ||
|
|
||
| bucket.create_file tmpfile, new_file_name, checksum: true | ||
|
|
||
| mock.verify | ||
| end | ||
| end | ||
|
|
||
| it "creates a file with attributes" do | ||
| new_file_name = random_file_path | ||
|
|
||
|
|
@@ -595,9 +666,11 @@ | |
| new_file_name = random_file_path | ||
|
|
||
| Tempfile.create ["google-cloud", ".txt"] do |tmpfile| | ||
|
|
||
| crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile | ||
| mock = Minitest::Mock.new | ||
| mock.expect :insert_object, create_file_gapi(bucket_user_project.name, new_file_name), | ||
| [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: tmpfile, user_project: "test", options: {retries: 0}) | ||
| [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, user_project: "test", options: {retries: 0}) | ||
|
|
||
| bucket_user_project.service.mocked_service = mock | ||
|
|
||
|
|
@@ -608,13 +681,13 @@ | |
| end | ||
| end | ||
|
|
||
| it "creates an file with a StringIO" do | ||
| it "creates a file with StringIO" do | ||
| new_file_name = random_file_path | ||
| new_file_contents = StringIO.new | ||
|
|
||
| new_file_contents = StringIO.new("Hello world string_io") | ||
| crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for new_file_contents | ||
| mock = Minitest::Mock.new | ||
| mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), | ||
| [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) | ||
| [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) | ||
|
|
||
| bucket.service.mocked_service = mock | ||
|
|
||
|
|
@@ -1416,7 +1489,11 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, | |
| content_encoding: nil, content_language: nil, | ||
| content_type: nil, crc32c: nil, md5: nil, metadata: nil, | ||
| storage_class: nil, temporary_hold: nil, | ||
| event_based_hold: nil | ||
| event_based_hold: nil, checksum: nil | ||
|
|
||
| # If no checksum type or specific value is provided, the default will be set to crc32c. | ||
| # If the checksum is set to false, it will be disabled. | ||
| crc32c ||= set_crc32c_as_default md5, crc32c, checksum | ||
|
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. This change, while intended to support default checksums in tests, will likely cause existing tests for empty file creation (e.g., This logic needs to be more nuanced to avoid applying a default checksum for mocks of empty file uploads. You might need to modify |
||
| params = { | ||
| cache_control: cache_control, content_type: content_type, | ||
| content_disposition: content_disposition, md5_hash: md5, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.