|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -import pytest |
16 | | -from google.auth.exceptions import MutualTLSChannelError |
| 15 | +from google.api_core.gapic_v1 import client_utils |
| 16 | +from google.api_core import universe |
17 | 17 |
|
18 | | -from google.api_core.gapic_v1.client_utils import ( |
19 | | - get_api_endpoint, |
20 | | - get_default_mtls_endpoint, |
21 | | -) |
22 | 18 |
|
23 | | - |
24 | | -def test_get_default_mtls_endpoint(): |
25 | | - # Test valid API endpoints |
26 | | - assert get_default_mtls_endpoint("foo.googleapis.com") == "foo.mtls.googleapis.com" |
27 | | - assert ( |
28 | | - get_default_mtls_endpoint("foo.sandbox.googleapis.com") |
29 | | - == "foo.mtls.sandbox.googleapis.com" |
30 | | - ) |
31 | | - # Test case-insensitivity |
32 | | - assert get_default_mtls_endpoint("foo.GoogleAPIs.com") == "foo.mtls.googleapis.com" |
33 | | - assert ( |
34 | | - get_default_mtls_endpoint("foo.Sandbox.GoogleAPIs.com") |
35 | | - == "foo.mtls.sandbox.googleapis.com" |
36 | | - ) |
37 | | - |
38 | | - # Test valid API endpoints with schemes |
39 | | - assert ( |
40 | | - get_default_mtls_endpoint("https://foo.googleapis.com") |
41 | | - == "https://foo.mtls.googleapis.com" |
42 | | - ) |
43 | | - assert ( |
44 | | - get_default_mtls_endpoint("http://foo.googleapis.com:8080/v1") |
45 | | - == "http://foo.mtls.googleapis.com:8080/v1" |
46 | | - ) |
47 | | - |
48 | | - # Test valid API endpoints with ports |
49 | | - assert ( |
50 | | - get_default_mtls_endpoint("foo.googleapis.com:443") |
51 | | - == "foo.mtls.googleapis.com:443" |
52 | | - ) |
53 | | - assert ( |
54 | | - get_default_mtls_endpoint("foo.sandbox.googleapis.com:443") |
55 | | - == "foo.mtls.sandbox.googleapis.com:443" |
56 | | - ) |
57 | | - # Test case-insensitivity with ports |
58 | | - assert ( |
59 | | - get_default_mtls_endpoint("foo.GoogleAPIs.com:443") |
60 | | - == "foo.mtls.googleapis.com:443" |
61 | | - ) |
62 | | - assert ( |
63 | | - get_default_mtls_endpoint("foo.Sandbox.GoogleAPIs.com:443") |
64 | | - == "foo.mtls.sandbox.googleapis.com:443" |
65 | | - ) |
66 | | - |
67 | | - # Test endpoints that shouldn't be converted |
68 | | - assert ( |
69 | | - get_default_mtls_endpoint("foo.mtls.googleapis.com") |
70 | | - == "foo.mtls.googleapis.com" |
71 | | - ) |
72 | | - assert get_default_mtls_endpoint("foo.com") == "foo.com" |
73 | | - assert get_default_mtls_endpoint("foo.com:8080") == "foo.com:8080" |
74 | | - assert get_default_mtls_endpoint("/") == "/" |
75 | | - |
76 | | - # Test empty/None endpoints |
77 | | - assert get_default_mtls_endpoint("") == "" |
78 | | - assert get_default_mtls_endpoint(None) is None |
79 | | - |
80 | | - |
81 | | -@pytest.mark.parametrize( |
82 | | - "api_override,universe_domain,default_universe,default_mtls_endpoint,default_endpoint_template,use_mtls,expected", |
83 | | - [ |
84 | | - ( |
85 | | - "foo.com", |
86 | | - "googleapis.com", |
87 | | - "googleapis.com", |
88 | | - "foo.mtls.googleapis.com", |
89 | | - "foo.{UNIVERSE_DOMAIN}", |
90 | | - True, |
91 | | - "foo.com", |
92 | | - ), |
93 | | - ( |
94 | | - None, |
95 | | - "googleapis.com", |
96 | | - "googleapis.com", |
97 | | - "foo.mtls.googleapis.com", |
98 | | - "foo.{UNIVERSE_DOMAIN}", |
99 | | - True, |
100 | | - "foo.mtls.googleapis.com", |
101 | | - ), |
102 | | - ( |
103 | | - None, |
104 | | - "googleapis.com", |
105 | | - "googleapis.com", |
106 | | - "foo.mtls.googleapis.com", |
107 | | - "foo.{UNIVERSE_DOMAIN}", |
108 | | - False, |
109 | | - "foo.googleapis.com", |
110 | | - ), |
111 | | - ( |
112 | | - None, |
113 | | - "bar.com", |
114 | | - "googleapis.com", |
115 | | - "foo.mtls.googleapis.com", |
116 | | - "foo.{UNIVERSE_DOMAIN}", |
117 | | - True, |
118 | | - MutualTLSChannelError, |
119 | | - ), |
120 | | - ( |
121 | | - None, |
122 | | - "googleapis.com", |
123 | | - "googleapis.com", |
124 | | - None, |
125 | | - "foo.{UNIVERSE_DOMAIN}", |
126 | | - True, |
127 | | - ValueError, |
128 | | - ), |
129 | | - ], |
130 | | -) |
131 | | -def test_get_api_endpoint( |
132 | | - api_override, |
133 | | - universe_domain, |
134 | | - default_universe, |
135 | | - default_mtls_endpoint, |
136 | | - default_endpoint_template, |
137 | | - use_mtls, |
138 | | - expected, |
139 | | -): |
140 | | - if isinstance(expected, type) and issubclass(expected, Exception): |
141 | | - with pytest.raises(expected): |
142 | | - get_api_endpoint( |
143 | | - api_override, |
144 | | - universe_domain, |
145 | | - default_universe, |
146 | | - default_mtls_endpoint, |
147 | | - default_endpoint_template, |
148 | | - use_mtls, |
149 | | - ) |
150 | | - else: |
151 | | - assert ( |
152 | | - get_api_endpoint( |
153 | | - api_override, |
154 | | - universe_domain, |
155 | | - default_universe, |
156 | | - default_mtls_endpoint, |
157 | | - default_endpoint_template, |
158 | | - use_mtls, |
159 | | - ) |
160 | | - == expected |
161 | | - ) |
| 19 | +def test_exports(): |
| 20 | + assert client_utils.get_api_endpoint is universe.get_api_endpoint |
| 21 | + assert client_utils.get_default_mtls_endpoint is universe.get_default_mtls_endpoint |
| 22 | + assert client_utils.get_universe_domain is universe.get_universe_domain |
0 commit comments