Skip to content

Commit 02a972d

Browse files
authored
feat: add integration test for universe domain (#1346)
1 parent 85aa02f commit 02a972d

File tree

6 files changed

+108
-1
lines changed

6 files changed

+108
-1
lines changed

.kokoro/build.sh

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export API_VERSION_OVERRIDE
3434
export DUAL_REGION_LOC_1
3535
export DUAL_REGION_LOC_2
3636

37+
# Setup universe domain testing needed environment variables.
38+
export TEST_UNIVERSE_DOMAIN_CREDENTIAL=$(realpath ${KOKORO_GFILE_DIR}/secret_manager/client-library-test-universe-domain-credential)
39+
export TEST_UNIVERSE_DOMAIN=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-domain)
40+
export TEST_UNIVERSE_PROJECT_ID=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-project-id)
41+
export TEST_UNIVERSE_LOCATION=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-storage-location)
42+
43+
44+
3745
# Debug: show build environment
3846
env | grep KOKORO
3947

.kokoro/presubmit/system-3.8.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
env_vars: {
55
key: "NOX_SESSION"
66
value: "system-3.8"
7+
}
8+
9+
# Credentials needed to test universe domain.
10+
env_vars: {
11+
key: "SECRET_MANAGER_KEYS"
12+
value: "client-library-test-universe-domain-credential"
713
}

owlbot.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"noxfile.py",
4747
"CONTRIBUTING.rst",
4848
"README.rst",
49+
".kokoro/presubmit/system-3.8.cfg",
4950
".kokoro/samples/python3.6", # remove python 3.6 support
5051
".github/blunderbuss.yml", # blunderbuss assignment to python squad
5152
".github/workflows", # exclude gh actions as credentials are needed for tests
@@ -66,7 +67,15 @@
6667
6768
# Export dual region locations
6869
export DUAL_REGION_LOC_1
69-
export DUAL_REGION_LOC_2""")
70+
export DUAL_REGION_LOC_2
71+
72+
# Setup universe domain testing needed environment variables.
73+
export TEST_UNIVERSE_DOMAIN_CREDENTIAL=$(realpath ${KOKORO_GFILE_DIR}/secret_manager/client-library-test-universe-domain-credential)
74+
export TEST_UNIVERSE_DOMAIN=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-domain)
75+
export TEST_UNIVERSE_PROJECT_ID=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-project-id)
76+
export TEST_UNIVERSE_LOCATION=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-storage-location)
77+
78+
""")
7079

7180
s.replace(
7281
".coveragerc",

tests/system/_helpers.py

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
user_project = os.environ.get("GOOGLE_CLOUD_TESTS_USER_PROJECT")
3333
testing_mtls = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE") == "true"
34+
test_universe_domain = os.getenv("TEST_UNIVERSE_DOMAIN")
35+
test_universe_project_id = os.getenv("TEST_UNIVERSE_PROJECT_ID")
36+
test_universe_location = os.getenv("TEST_UNIVERSE_LOCATION")
37+
test_universe_domain_credential = os.getenv("TEST_UNIVERSE_DOMAIN_CREDENTIAL")
3438
signing_blob_content = b"This time for sure, Rocky!"
3539
is_api_endpoint_override = (
3640
_get_default_storage_base_url() != "https://storage.googleapis.com"

tests/system/conftest.py

+53
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,56 @@ def keyring(storage_client, kms_bucket, kms_client):
331331
except exceptions.NotFound:
332332
key = {"purpose": purpose}
333333
kms_client.create_crypto_key(keyring_path, key_name, key)
334+
335+
336+
@pytest.fixture(scope="function")
337+
def test_universe_domain():
338+
if _helpers.test_universe_domain is None:
339+
pytest.skip("TEST_UNIVERSE_DOMAIN not set in environment.")
340+
return _helpers.test_universe_domain
341+
342+
343+
@pytest.fixture(scope="function")
344+
def test_universe_project_id():
345+
if _helpers.test_universe_project_id is None:
346+
pytest.skip("TEST_UNIVERSE_PROJECT_ID not set in environment.")
347+
return _helpers.test_universe_project_id
348+
349+
350+
@pytest.fixture(scope="function")
351+
def test_universe_location():
352+
if _helpers.test_universe_location is None:
353+
pytest.skip("TEST_UNIVERSE_LOCATION not set in environment.")
354+
return _helpers.test_universe_location
355+
356+
357+
@pytest.fixture(scope="function")
358+
def test_universe_domain_credential():
359+
if _helpers.test_universe_domain_credential is None:
360+
pytest.skip("TEST_UNIVERSE_DOMAIN_CREDENTIAL not set in environment.")
361+
return _helpers.test_universe_domain_credential
362+
363+
364+
@pytest.fixture(scope="function")
365+
def universe_domain_credential(test_universe_domain_credential):
366+
from google.oauth2 import service_account
367+
368+
return service_account.Credentials.from_service_account_file(
369+
test_universe_domain_credential
370+
)
371+
372+
373+
@pytest.fixture(scope="function")
374+
def universe_domain_client(
375+
test_universe_domain, test_universe_project_id, universe_domain_credential
376+
):
377+
from google.cloud.storage import Client
378+
379+
client_options = {"universe_domain": test_universe_domain}
380+
ud_storage_client = Client(
381+
project=test_universe_project_id,
382+
credentials=universe_domain_credential,
383+
client_options=client_options,
384+
)
385+
with contextlib.closing(ud_storage_client):
386+
yield ud_storage_client

tests/system/test_client.py

+27
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,30 @@ def test_download_blob_to_file_w_etag(
184184
if_etag_match=blob.etag,
185185
)
186186
assert buffer.getvalue() == payload
187+
188+
189+
def test_client_universe_domain(
190+
universe_domain_client,
191+
test_universe_location,
192+
buckets_to_delete,
193+
blobs_to_delete,
194+
):
195+
bucket_name = _helpers.unique_name("gcp-systest-ud")
196+
ud_bucket = universe_domain_client.create_bucket(
197+
bucket_name, location=test_universe_location
198+
)
199+
buckets_to_delete.append(ud_bucket)
200+
201+
blob_name = _helpers.unique_name("gcp-systest-ud")
202+
blob = ud_bucket.blob(blob_name)
203+
payload = b"The quick brown fox jumps over the lazy dog"
204+
blob.upload_from_string(payload)
205+
blobs_to_delete.append(blob)
206+
207+
with tempfile.NamedTemporaryFile() as temp_f:
208+
with open(temp_f.name, "wb") as file_obj:
209+
universe_domain_client.download_blob_to_file(blob, file_obj)
210+
with open(temp_f.name, "rb") as file_obj:
211+
stored_contents = file_obj.read()
212+
213+
assert stored_contents == payload

0 commit comments

Comments
 (0)