Skip to content

Commit 88c4b82

Browse files
updating tests
1 parent 36ea00e commit 88c4b82

2 files changed

Lines changed: 32 additions & 13 deletions

File tree

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,14 @@
8989
bucket_gapi_with_key = bucket_gapi.dup
9090
bucket_gapi_with_key.encryption = encryption_gapi(key_name: kms_key)
9191
bucket_with_key = Google::Cloud::Storage::Bucket.from_gapi bucket_gapi_with_key, storage.service
92+
patch_bucket_gapi = Google::Apis::StorageV1::Bucket.new encryption: encryption_gapi(key_name: kms_key)
93+
patch_bucket_gapi = Google::Apis::StorageV1::Bucket.new(
94+
encryption: Google::Apis::StorageV1::Bucket::Encryption.new(
95+
default_kms_key_name: nil
96+
)
97+
)
9298
mock = Minitest::Mock.new
93-
mock.expect :patch_bucket, bucket_gapi do |name, patch_obj, **args|
94-
name == bucket_name && patch_obj.encryption&.default_kms_key_name.nil?
95-
end
99+
mock.expect :patch_bucket, bucket_gapi, [bucket_name, patch_bucket_gapi], **patch_bucket_args(options: {retries: 0})
96100

97101
bucket_with_key.service.mocked_service = mock
98102

@@ -123,9 +127,6 @@
123127
end
124128

125129
describe "encryption enforcement config" do
126-
let(:customer_managed_encryption) { Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig.new restriction_mode: "NotRestricted" }
127-
let(:customer_supplied_encryption) { Google::Apis::StorageV1::Bucket::Encryption::CustomerSuppliedEncryptionEnforcementConfig.new restriction_mode: "FullyRestricted" }
128-
let(:google_managed_encryption) { Google::Apis::StorageV1::Bucket::Encryption::GoogleManagedEncryptionEnforcementConfig.new restriction_mode: "NotRestricted" }
129130
let(:bucket_encryption) do
130131
Google::Apis::StorageV1::Bucket::Encryption.new(
131132
customer_managed_encryption_enforcement_config: customer_managed_encryption,
@@ -142,8 +143,8 @@
142143
end
143144

144145
it "knows its encryption enforcement config" do
145-
_(bucket.customer_managed_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
146-
_(bucket.customer_supplied_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
146+
_(bucket.customer_managed_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
147+
_(bucket.customer_supplied_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
147148
_(bucket.google_managed_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
148149
end
149150

@@ -163,13 +164,13 @@
163164
mock.expect :patch_bucket, returned_bucket_gapi, [bucket_name, patch_bucket_gapi], **patch_bucket_args(options: { retries: 0 })
164165

165166
bucket.service.mocked_service = mock
166-
_(bucket.customer_managed_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
167-
_(bucket.customer_supplied_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
167+
_(bucket.customer_managed_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
168+
_(bucket.customer_supplied_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
168169
_(bucket.google_managed_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
169170

170171
bucket.update_bucket_encryption_enforcement_config incoming_config
171-
_(bucket.customer_managed_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
172-
_(bucket.customer_supplied_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
172+
_(bucket.customer_managed_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
173+
_(bucket.customer_supplied_encryption_enforcement_config.restriction_mode).must_equal "NotRestricted"
173174
_(bucket.google_managed_encryption_enforcement_config.restriction_mode).must_equal "FullyRestricted"
174175

175176
mock.verify

google-cloud-storage/test/helper.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,24 @@ def download_http_resp gzip: nil
244244
OpenStruct.new(header: headers)
245245
end
246246

247+
def customer_managed_encryption
248+
Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig.new(
249+
restriction_mode: "FullyRestricted"
250+
)
251+
end
252+
253+
def customer_supplied_encryption
254+
Google::Apis::StorageV1::Bucket::Encryption::CustomerSuppliedEncryptionEnforcementConfig.new(
255+
restriction_mode: "NotRestricted"
256+
)
257+
end
258+
259+
def google_managed_encryption
260+
Google::Apis::StorageV1::Bucket::Encryption::GoogleManagedEncryptionEnforcementConfig.new(
261+
restriction_mode: "NotRestricted"
262+
)
263+
end
264+
247265
def encryption_gapi(key_name: nil,
248266
customer_managed_config_restriction_mode: nil,
249267
customer_supplied_config_restriction_mode: nil,
@@ -258,7 +276,7 @@ def encryption_gapi(key_name: nil,
258276
customer_managed_encryption_enforcement_config: cm_config,
259277
customer_supplied_encryption_enforcement_config: cs_config,
260278
google_managed_encryption_enforcement_config: gm_config
261-
}.compact # This removes the nil values so the API doesn't get empty configs
279+
}.compact
262280

263281
Google::Apis::StorageV1::Bucket::Encryption.new(**params)
264282
end

0 commit comments

Comments
 (0)