@@ -141,67 +141,60 @@ func TestGetGRPCTransportConfigAndEndpoint(t *testing.T) {
141
141
Desc string
142
142
InputSettings * DialSettings
143
143
S2ARespFunc func () (string , error )
144
- MTLSEnabled func () bool
145
144
WantEndpoint string
146
145
}{
147
146
{
148
- "no client cert, endpoint is MTLS enabled, S2A address not empty " ,
147
+ "has client cert" ,
149
148
& DialSettings {
150
149
DefaultMTLSEndpoint : testMTLSEndpoint ,
151
150
DefaultEndpoint : testRegularEndpoint ,
151
+ ClientCertSource : dummyClientCertSource ,
152
152
},
153
153
validConfigResp ,
154
- func () bool { return true },
155
154
testMTLSEndpoint ,
156
155
},
157
156
{
158
- "has client cert" ,
157
+ "no client cert, S2A address not empty " ,
159
158
& DialSettings {
160
159
DefaultMTLSEndpoint : testMTLSEndpoint ,
161
160
DefaultEndpoint : testRegularEndpoint ,
162
- ClientCertSource : dummyClientCertSource ,
163
161
},
164
162
validConfigResp ,
165
- func () bool { return true },
166
163
testMTLSEndpoint ,
167
164
},
168
165
{
169
- "no client cert, endpoint is not MTLS enabled " ,
166
+ "no client cert, S2A address empty " ,
170
167
& DialSettings {
171
168
DefaultMTLSEndpoint : testMTLSEndpoint ,
172
169
DefaultEndpoint : testRegularEndpoint ,
173
170
},
174
- validConfigResp ,
175
- func () bool { return false },
171
+ invalidConfigResp ,
176
172
testRegularEndpoint ,
177
173
},
178
174
{
179
- "no client cert, endpoint is MTLS enabled, S2A address empty " ,
175
+ "no client cert, S2A address not empty, override endpoint " ,
180
176
& DialSettings {
181
177
DefaultMTLSEndpoint : testMTLSEndpoint ,
182
178
DefaultEndpoint : testRegularEndpoint ,
179
+ Endpoint : testOverrideEndpoint ,
183
180
},
184
- invalidConfigResp ,
185
- func () bool { return true },
186
- testRegularEndpoint ,
181
+ validConfigResp ,
182
+ testOverrideEndpoint ,
187
183
},
188
184
{
189
- "no client cert, endpoint is MTLS enabled, S2A address not empty, override endpoint " ,
185
+ "no client cert, S2A address not empty, DefaultMTLSEndpoint not set " ,
190
186
& DialSettings {
191
- DefaultMTLSEndpoint : testMTLSEndpoint ,
187
+ DefaultMTLSEndpoint : "" ,
192
188
DefaultEndpoint : testRegularEndpoint ,
193
- Endpoint : testOverrideEndpoint ,
194
189
},
195
190
validConfigResp ,
196
- func () bool { return true },
197
- testOverrideEndpoint ,
191
+ testRegularEndpoint ,
198
192
},
199
193
}
200
194
defer setupTest ()()
201
195
202
196
for _ , tc := range testCases {
203
197
httpGetMetadataMTLSConfig = tc .S2ARespFunc
204
- mtlsEndpointEnabledForS2A = tc .MTLSEnabled
205
198
if tc .InputSettings .ClientCertSource != nil {
206
199
os .Setenv ("GOOGLE_API_USE_CLIENT_CERTIFICATE" , "true" )
207
200
} else {
@@ -221,21 +214,9 @@ func TestGetHTTPTransportConfigAndEndpoint_s2a(t *testing.T) {
221
214
Desc string
222
215
InputSettings * DialSettings
223
216
S2ARespFunc func () (string , error )
224
- MTLSEnabled func () bool
225
217
WantEndpoint string
226
218
DialFuncNil bool
227
219
}{
228
- {
229
- "no client cert, endpoint is MTLS enabled, S2A address not empty" ,
230
- & DialSettings {
231
- DefaultMTLSEndpoint : testMTLSEndpoint ,
232
- DefaultEndpoint : testRegularEndpoint ,
233
- },
234
- validConfigResp ,
235
- func () bool { return true },
236
- testMTLSEndpoint ,
237
- false ,
238
- },
239
220
{
240
221
"has client cert" ,
241
222
& DialSettings {
@@ -244,43 +225,39 @@ func TestGetHTTPTransportConfigAndEndpoint_s2a(t *testing.T) {
244
225
ClientCertSource : dummyClientCertSource ,
245
226
},
246
227
validConfigResp ,
247
- func () bool { return true },
248
228
testMTLSEndpoint ,
249
229
true ,
250
230
},
251
231
{
252
- "no client cert, endpoint is not MTLS enabled " ,
232
+ "no client cert, S2A address not empty " ,
253
233
& DialSettings {
254
234
DefaultMTLSEndpoint : testMTLSEndpoint ,
255
235
DefaultEndpoint : testRegularEndpoint ,
256
236
},
257
237
validConfigResp ,
258
- func () bool { return false },
259
- testRegularEndpoint ,
260
- true ,
238
+ testMTLSEndpoint ,
239
+ false ,
261
240
},
262
241
{
263
- "no client cert, endpoint is MTLS enabled, S2A address empty" ,
242
+ "no client cert, S2A address empty" ,
264
243
& DialSettings {
265
244
DefaultMTLSEndpoint : testMTLSEndpoint ,
266
245
DefaultEndpoint : testRegularEndpoint ,
267
246
},
268
247
invalidConfigResp ,
269
- func () bool { return true },
270
248
testRegularEndpoint ,
271
249
true ,
272
250
},
273
251
{
274
- "no client cert, endpoint is MTLS enabled, S2A address not empty, override endpoint" ,
252
+ "no client cert, S2A address not empty, override endpoint" ,
275
253
& DialSettings {
276
254
DefaultMTLSEndpoint : testMTLSEndpoint ,
277
255
DefaultEndpoint : testRegularEndpoint ,
278
256
Endpoint : testOverrideEndpoint ,
279
257
},
280
258
validConfigResp ,
281
- func () bool { return true },
282
259
testOverrideEndpoint ,
283
- false ,
260
+ true ,
284
261
},
285
262
{
286
263
"no client cert, S2A address not empty, but DefaultMTLSEndpoint is not set" ,
@@ -289,30 +266,17 @@ func TestGetHTTPTransportConfigAndEndpoint_s2a(t *testing.T) {
289
266
DefaultEndpoint : testRegularEndpoint ,
290
267
},
291
268
validConfigResp ,
292
- func () bool { return true },
293
269
testRegularEndpoint ,
294
270
true ,
295
271
},
296
272
{
297
- "no client cert, S2A address not empty, override endpoint is set" ,
298
- & DialSettings {
299
- DefaultMTLSEndpoint : "" ,
300
- Endpoint : testOverrideEndpoint ,
301
- },
302
- validConfigResp ,
303
- func () bool { return true },
304
- testOverrideEndpoint ,
305
- false ,
306
- },
307
- {
308
- "no client cert, endpoint is MTLS enabled, S2A address not empty, custom HTTP client" ,
273
+ "no client cert, S2A address not empty, custom HTTP client" ,
309
274
& DialSettings {
310
275
DefaultMTLSEndpoint : testMTLSEndpoint ,
311
276
DefaultEndpoint : testRegularEndpoint ,
312
277
HTTPClient : http .DefaultClient ,
313
278
},
314
279
validConfigResp ,
315
- func () bool { return true },
316
280
testRegularEndpoint ,
317
281
true ,
318
282
},
@@ -322,7 +286,6 @@ func TestGetHTTPTransportConfigAndEndpoint_s2a(t *testing.T) {
322
286
323
287
for _ , tc := range testCases {
324
288
httpGetMetadataMTLSConfig = tc .S2ARespFunc
325
- mtlsEndpointEnabledForS2A = tc .MTLSEnabled
326
289
if tc .InputSettings .ClientCertSource != nil {
327
290
os .Setenv ("GOOGLE_API_USE_CLIENT_CERTIFICATE" , "true" )
328
291
} else {
@@ -344,7 +307,6 @@ func TestGetHTTPTransportConfigAndEndpoint_s2a(t *testing.T) {
344
307
}
345
308
346
309
func setupTest () func () {
347
- oldDefaultMTLSEnabled := mtlsEndpointEnabledForS2A
348
310
oldHTTPGet := httpGetMetadataMTLSConfig
349
311
oldExpiry := configExpiry
350
312
oldUseS2A := os .Getenv (googleAPIUseS2AEnv )
@@ -355,7 +317,6 @@ func setupTest() func() {
355
317
356
318
return func () {
357
319
httpGetMetadataMTLSConfig = oldHTTPGet
358
- mtlsEndpointEnabledForS2A = oldDefaultMTLSEnabled
359
320
configExpiry = oldExpiry
360
321
os .Setenv (googleAPIUseS2AEnv , oldUseS2A )
361
322
os .Setenv ("GOOGLE_API_USE_CLIENT_CERTIFICATE" , oldUseClientCert )
0 commit comments