@@ -332,24 +332,20 @@ func MeshNamespacesMustBeReady(t *testing.T, c client.Client, timeoutConfig conf
332
332
//
333
333
// The test will fail if these conditions are not met before the timeouts.
334
334
// Note that this also returns a Gateway address to use, but it takes the port
335
- // from the first listener it finds. Therefore, if the Gateway has multiple listeners,
336
- // don't use this function unless you can ignore the port and allow the url
337
- // scheme to determine the default port to use in a URL. Set parameter `usePort` to
338
- // false if there are multiple listeners, and true if there is only one listener.
335
+ // from the first listener it finds. Set parameter `usePort` to false if there
336
+ // are multiple listeners, and true if there is only one listener.
339
337
func GatewayAndRoutesMustBeAccepted (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , controllerName string , gw GatewayRef , routeType any , usePort bool , routeNNs ... types.NamespacedName ) string {
340
338
t .Helper ()
341
339
342
- var err error
343
- var gwAddr string
344
-
345
340
RouteTypeMustHaveParentsField (t , routeType )
341
+ gwAddr , err := WaitForGatewayAddress (t , c , timeoutConfig , gw )
342
+ require .NoErrorf (t , err , "timed out waiting for Gateway address to be assigned" )
343
+
346
344
// If the Gateway has multiple listeners, get a portless gwAddr.
345
+ // Otherwise, you get the first listener's port, which might not be the one you want.
347
346
if ! usePort {
348
- gwAddr , err = WaitForGatewayAddressMultipleListeners (t , c , timeoutConfig , gw )
349
- } else {
350
- gwAddr , err = WaitForGatewayAddress (t , c , timeoutConfig , gw )
347
+ gwAddr , _ , _ = strings .Cut (gwAddr , ":" )
351
348
}
352
- require .NoErrorf (t , err , "timed out waiting for Gateway address to be assigned" )
353
349
354
350
ns := gatewayv1 .Namespace (gw .Namespace )
355
351
kind := gatewayv1 .Kind ("Gateway" )
@@ -416,12 +412,6 @@ func GatewayAndHTTPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutCo
416
412
return GatewayAndRoutesMustBeAccepted (t , c , timeoutConfig , controllerName , gw , & gatewayv1.HTTPRoute {}, true , routeNNs ... )
417
413
}
418
414
419
- // GatewayAndHTTPRoutesMustBeAcceptedMultipleListeners is the same as GatewayAndHTTPRoutesMustBeAccepted except it does not
420
- // return the port in the gateway string. With multiple listeners, port varies and some tests can't succeed using the returned port.
421
- func GatewayAndHTTPRoutesMustBeAcceptedMultipleListeners (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , controllerName string , gw GatewayRef , routeNNs ... types.NamespacedName ) string {
422
- return GatewayAndRoutesMustBeAccepted (t , c , timeoutConfig , controllerName , gw , & gatewayv1.HTTPRoute {}, false , routeNNs ... )
423
- }
424
-
425
415
// GatewayAndUDPRoutesMustBeAccepted waits until the specified Gateway has an IP
426
416
// address assigned to it and the UDPRoute has a ParentRef referring to the
427
417
// Gateway. The test will fail if these conditions are not met before the
@@ -431,8 +421,7 @@ func GatewayAndUDPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutCon
431
421
}
432
422
433
423
// WaitForGatewayAddress waits until at least one IP Address has been set in the
434
- // status of the specified Gateway. Use when there is only one listener in the
435
- // Gateway.
424
+ // status of the specified Gateway.
436
425
func WaitForGatewayAddress (t * testing.T , client client.Client , timeoutConfig config.TimeoutConfig , gwRef GatewayRef ) (string , error ) {
437
426
t .Helper ()
438
427
@@ -467,34 +456,6 @@ func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig con
467
456
return net .JoinHostPort (ipAddr , port ), waitErr
468
457
}
469
458
470
- // WaitForGatewayAddressMultipleListeners waits until at least one IP Address has been set in the
471
- // status of the specified Gateway and returns it without a port. A port interferes when
472
- // there are multiple listeners, e.g if the first listener is HTTP/80 but we want to be using another
473
- // listener with HTTPS/443, we can't send a request to https://gwaddr:80. But we can send a request
474
- // to https://gwaddr and expect it to succeed by using the default port for HTTPS.
475
- func WaitForGatewayAddressMultipleListeners (t * testing.T , client client.Client , timeoutConfig config.TimeoutConfig , gwRef GatewayRef ) (string , error ) {
476
- t .Helper ()
477
-
478
- var ipAddr string
479
- waitErr := wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , timeoutConfig .GatewayMustHaveAddress , true , func (ctx context.Context ) (bool , error ) {
480
- gw , err := getGatewayStatus (t , ctx , client , gwRef )
481
- if gw == nil {
482
- // The returned error is nil if the Gateway conditions don't have the latest observed generation.
483
- return false , err
484
- }
485
-
486
- for _ , address := range gw .Status .Addresses {
487
- if address .Type != nil && (* address .Type == gatewayv1 .IPAddressType || * address .Type == v1alpha2 .HostnameAddressType ) {
488
- ipAddr = address .Value
489
- return true , nil
490
- }
491
- }
492
- return false , nil
493
- })
494
- require .NoErrorf (t , waitErr , "error waiting for Gateway to have at least one IP address in status" )
495
- return ipAddr , waitErr
496
- }
497
-
498
459
func getGatewayStatus (t * testing.T , ctx context.Context , client client.Client , gwRef GatewayRef ) (* gatewayv1.Gateway , error ) {
499
460
gw := & gatewayv1.Gateway {}
500
461
err := client .Get (ctx , gwRef .NamespacedName , gw )
0 commit comments