|
26 | 26 | from google.cloud.bigtable_v2.types import ReadRowsResponse |
27 | 27 | from google.cloud.bigtable.data.read_rows_query import ReadRowsQuery |
28 | 28 | from google.api_core import exceptions as core_exceptions |
| 29 | +from google.api_core import client_options |
29 | 30 | from google.cloud.bigtable.data.exceptions import InvalidChunk |
30 | 31 | from google.cloud.bigtable.data.exceptions import _MutateRowsIncomplete |
31 | 32 | from google.cloud.bigtable.data.mutations import DeleteAllFromRow |
@@ -1038,6 +1039,97 @@ def test_client_ctor_sync(self): |
1038 | 1039 | assert client.project == "project-id" |
1039 | 1040 | assert client._channel_refresh_task is None |
1040 | 1041 |
|
| 1042 | + @CrossSync.pytest |
| 1043 | + async def test_default_universe_domain(self): |
| 1044 | + """ |
| 1045 | + When not passed, universe_domain should default to googleapis.com |
| 1046 | + """ |
| 1047 | + async with self._make_client(project="project-id", credentials=None) as client: |
| 1048 | + assert client.universe_domain == "googleapis.com" |
| 1049 | + assert client.api_endpoint == "bigtable.googleapis.com" |
| 1050 | + |
| 1051 | + @CrossSync.pytest |
| 1052 | + async def test_custom_universe_domain(self): |
| 1053 | + """test with a customized universe domain value and emulator enabled""" |
| 1054 | + universe_domain = "test-universe.test" |
| 1055 | + options = client_options.ClientOptions(universe_domain=universe_domain) |
| 1056 | + async with self._make_client( |
| 1057 | + project="project_id", |
| 1058 | + client_options=options, |
| 1059 | + use_emulator=True, |
| 1060 | + credentials=None, |
| 1061 | + ) as client: |
| 1062 | + assert client.universe_domain == universe_domain |
| 1063 | + assert client.api_endpoint == f"bigtable.{universe_domain}" |
| 1064 | + |
| 1065 | + @CrossSync.pytest |
| 1066 | + async def test_configured_universe_domain_matches_GDU(self): |
| 1067 | + """that configured universe domain succeeds with matched GDU credentials.""" |
| 1068 | + universe_domain = "googleapis.com" |
| 1069 | + options = client_options.ClientOptions(universe_domain=universe_domain) |
| 1070 | + async with self._make_client( |
| 1071 | + project="project_id", client_options=options, credentials=None |
| 1072 | + ) as client: |
| 1073 | + assert client.universe_domain == "googleapis.com" |
| 1074 | + assert client.api_endpoint == "bigtable.googleapis.com" |
| 1075 | + |
| 1076 | + @CrossSync.pytest |
| 1077 | + async def test_credential_universe_domain_matches_GDU(self): |
| 1078 | + """Test with credentials""" |
| 1079 | + creds = AnonymousCredentials() |
| 1080 | + creds._universe_domain = "googleapis.com" |
| 1081 | + async with self._make_client(project="project_id", credentials=creds) as client: |
| 1082 | + assert client.universe_domain == "googleapis.com" |
| 1083 | + assert client.api_endpoint == "bigtable.googleapis.com" |
| 1084 | + |
| 1085 | + @CrossSync.pytest |
| 1086 | + async def test_anomynous_credential_universe_domain(self): |
| 1087 | + """Anomynopus credentials should use default universe domain""" |
| 1088 | + creds = AnonymousCredentials() |
| 1089 | + async with self._make_client(project="project_id", credentials=creds) as client: |
| 1090 | + assert client.universe_domain == "googleapis.com" |
| 1091 | + assert client.api_endpoint == "bigtable.googleapis.com" |
| 1092 | + |
| 1093 | + @CrossSync.pytest |
| 1094 | + async def test_configured_universe_domain_mismatched_credentials(self): |
| 1095 | + """Test that configured universe domain errors with mismatched universe |
| 1096 | + domain credentials. |
| 1097 | + """ |
| 1098 | + universe_domain = "test-universe.test" |
| 1099 | + options = client_options.ClientOptions(universe_domain=universe_domain) |
| 1100 | + creds = AnonymousCredentials() |
| 1101 | + creds._universe_domain = "different-universe" |
| 1102 | + with pytest.raises(ValueError) as exc: |
| 1103 | + self._make_client( |
| 1104 | + project="project_id", |
| 1105 | + client_options=options, |
| 1106 | + use_emulator=False, |
| 1107 | + credentials=creds, |
| 1108 | + ) |
| 1109 | + err_msg = ( |
| 1110 | + f"The configured universe domain ({universe_domain}) does " |
| 1111 | + "not match the universe domain found in the credentials " |
| 1112 | + f"({creds.universe_domain}). If you haven't " |
| 1113 | + "configured the universe domain explicitly, `googleapis.com` " |
| 1114 | + "is the default." |
| 1115 | + ) |
| 1116 | + assert exc.value.args[0] == err_msg |
| 1117 | + |
| 1118 | + @CrossSync.pytest |
| 1119 | + async def test_configured_universe_domain_matches_credentials(self): |
| 1120 | + """Test that configured universe domain succeeds with matching universe |
| 1121 | + domain credentials. |
| 1122 | + """ |
| 1123 | + universe_domain = "test-universe.test" |
| 1124 | + options = client_options.ClientOptions(universe_domain=universe_domain) |
| 1125 | + creds = AnonymousCredentials() |
| 1126 | + creds._universe_domain = universe_domain |
| 1127 | + async with self._make_client( |
| 1128 | + project="project_id", credentials=creds, client_options=options |
| 1129 | + ) as client: |
| 1130 | + assert client.universe_domain == universe_domain |
| 1131 | + assert client.api_endpoint == f"bigtable.{universe_domain}" |
| 1132 | + |
1041 | 1133 |
|
1042 | 1134 | @CrossSync.convert_class("TestTable", add_mapping_for_name="TestTable") |
1043 | 1135 | class TestTableAsync: |
|
0 commit comments