Skip to content

Commit acf92dd

Browse files
refactoring tests
1 parent 3fb0ccf commit acf92dd

2 files changed

Lines changed: 6 additions & 23 deletions

File tree

google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,7 @@
163163
returned_bucket_gapi.encryption = bucket_gapi.encryption.dup
164164
returned_bucket_gapi.encryption.google_managed_encryption_enforcement_config = patch_bucket_gapi.encryption.google_managed_encryption_enforcement_config
165165

166-
mock.expect :update_bucket, returned_bucket_gapi do |name, patch_obj, **kwargs|
167-
cm_config = patch_obj.encryption.customer_managed_encryption_enforcement_config
168-
cs_config = patch_obj.encryption.customer_supplied_encryption_enforcement_config
169-
gm_config = patch_obj.encryption.google_managed_encryption_enforcement_config
170-
171-
end
166+
mock.expect(:update_bucket, returned_bucket_gapi) { |name,**| name == bucket_name}
172167

173168
bucket.service.mocked_service = mock
174169
_(bucket.customer_managed_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
@@ -178,7 +173,6 @@
178173
bucket.update do |b|
179174
b.google_managed_encryption_enforcement_config = incoming_config
180175
end
181-
# bucket.update_bucket_encryption_enforcement_config incoming_config
182176
_(bucket.customer_managed_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
183177
_(bucket.customer_supplied_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
184178
_(bucket.google_managed_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
@@ -206,23 +200,12 @@
206200
initial_bucket_gapi = bucket_gapi.dup
207201
initial_bucket_gapi.encryption = bucket_encryption.dup
208202
initial_bucket_gapi.encryption.default_kms_key_name = kms_key
209-
210203
bucket_with_configs_and_key = Google::Cloud::Storage::Bucket.from_gapi initial_bucket_gapi, storage.service
211204

212205
returned_bucket_gapi = bucket_gapi.dup
213206
returned_bucket_gapi.encryption = Google::Apis::StorageV1::Bucket::Encryption.new default_kms_key_name: kms_key
214207

215-
mock.expect :update_bucket, returned_bucket_gapi do |name, patch_obj, **kwargs|
216-
cm_config = patch_obj.encryption.customer_managed_encryption_enforcement_config
217-
cs_config = patch_obj.encryption.customer_supplied_encryption_enforcement_config
218-
gm_config = patch_obj.encryption.google_managed_encryption_enforcement_config
219-
220-
name == bucket_name &&
221-
(cm_config == {} || cm_config.nil?) &&
222-
(cs_config == {} || cs_config.nil?) &&
223-
(gm_config == {} || gm_config.nil?) &&
224-
patch_obj.encryption.default_kms_key_name == kms_key
225-
end
208+
mock.expect(:update_bucket, returned_bucket_gapi) { |name, patch_obj, **| name == bucket_name && patch_obj.encryption.default_kms_key_name == kms_key }
226209

227210
bucket_with_configs_and_key.service.mocked_service = mock
228211

google-cloud-storage/test/helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,21 @@ def download_http_resp gzip: nil
245245
end
246246

247247
def customer_managed_encryption
248-
Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig.new(
248+
Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig.new(
249249
restriction_mode: "FullyRestricted"
250-
)
250+
)
251251
end
252252

253253
def customer_supplied_encryption
254254
Google::Apis::StorageV1::Bucket::Encryption::CustomerSuppliedEncryptionEnforcementConfig.new(
255255
restriction_mode: "NotRestricted"
256-
)
256+
)
257257
end
258258

259259
def google_managed_encryption
260260
Google::Apis::StorageV1::Bucket::Encryption::GoogleManagedEncryptionEnforcementConfig.new(
261261
restriction_mode: "NotRestricted"
262-
)
262+
)
263263
end
264264

265265
def encryption_gapi key_name: nil

0 commit comments

Comments
 (0)