Skip to content

Commit 6c7f63e

Browse files
authored
fix: harden storage test fixtures (GoogleCloudPlatform#3039)
* fix: improve UBLA test fixtures * fix: improve IAM test fixtures
1 parent cbbf5de commit 6c7f63e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

storage/cloud-client/iam_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pytest
1717
import re
1818
import time
19+
import uuid
1920

2021
import storage_remove_bucket_iam_member
2122
import storage_add_bucket_iam_member
@@ -32,8 +33,11 @@
3233

3334
@pytest.fixture
3435
def bucket():
35-
bucket_name = "test-iam-" + str(int(time.time()))
36-
bucket = storage.Client().create_bucket(bucket_name)
36+
bucket = None
37+
while bucket is None or bucket.exists():
38+
bucket_name = "test-iam-{}".format(uuid.uuid4())
39+
bucket = storage.Client().bucket(bucket_name)
40+
bucket.create()
3741
bucket.iam_configuration.uniform_bucket_level_access_enabled = True
3842
bucket.patch()
3943
yield bucket

storage/cloud-client/uniform_bucket_level_access_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525

2626
@pytest.fixture()
2727
def bucket():
28-
"""Creates a test bucket and deletes it upon completion."""
29-
client = storage.Client()
30-
bucket_name = "uniform-bucket-level-access-" + str(int(time.time()))
31-
bucket = client.create_bucket(bucket_name)
28+
"""Yields a bucket that is deleted after the test completes."""
29+
bucket = None
30+
while bucket is None or bucket.exists():
31+
bucket_name = "uniform-bucket-level-access-{}".format(int(time.time()))
32+
bucket = storage.Client().bucket(bucket_name)
33+
bucket.create()
3234
yield bucket
3335
time.sleep(3)
3436
bucket.delete(force=True)

0 commit comments

Comments
 (0)