shunping commented on code in PR #31344:
URL: https://github.com/apache/beam/pull/31344#discussion_r1608363913


##########
sdks/python/apache_beam/io/gcp/gcsio_integration_test.py:
##########
@@ -141,6 +143,43 @@ def test_batch_copy_and_delete(self):
       self.assertFalse(
           result[1], 're-delete should not throw error: %s' % result[1])
 
+  @pytest.mark.it_postcommit
+  @mock.patch('apache_beam.io.gcp.gcsio.default_gcs_bucket_name')
+  def test_create_default_bucket(self, mock_default_gcs_bucket_name):
+    google_cloud_options = self.test_pipeline.options.view_as(
+        GoogleCloudOptions)
+    # overwrite kms option here, because get_or_create_default_gcs_bucket()
+    # requires this option unset.
+    google_cloud_options.dataflow_kms_key = None
+
+    import random
+    from hashlib import md5
+    # Add a random number to avoid collision if multiple test instances
+    # are run at the same time. To avoid too many dangling buckets if bucket
+    # removal fails, we limit the max number of possible bucket names in this
+    # test to 1000.
+    overridden_bucket_name = 'gcsio-it-%d-%s-%s' % (
+        random.randint(0, 999),
+        google_cloud_options.region,
+        md5(google_cloud_options.project.encode('utf8')).hexdigest())
+
+    mock_default_gcs_bucket_name.return_value = overridden_bucket_name
+
+    # remove the existing bucket with the same name as the default bucket
+    existing_bucket = self.gcsio.get_bucket(overridden_bucket_name)
+    if existing_bucket:
+      existing_bucket.delete()
+
+    bucket = gcsio.get_or_create_default_gcs_bucket(google_cloud_options)

Review Comment:
   Good idea. Added the check. PTAL



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to