@@ -1249,32 +1249,43 @@ func TestProcessSecurityPolicyObjectRefs(t *testing.T) {
12491249}
12501250
12511251func TestProcessServiceClusterForGatewayClass (t * testing.T ) {
1252+ gcName := "merged-gc"
1253+ nsName := "envoy-gateway-system"
12521254testCases := []struct {
12531255name string
12541256gatewayClass * gwapiv1.GatewayClass
12551257envoyProxy * egv1a1.EnvoyProxy
12561258expectedSvcName string
1259+ serviceCluster []client.Object
12571260}{
12581261{
12591262name :"when merged gateways and no hardcoded svc name is used" ,
12601263gatewayClass :& gwapiv1.GatewayClass {
12611264ObjectMeta : metav1.ObjectMeta {
1262- Name :"merged-gc" ,
1265+ Name :gcName ,
12631266},
12641267},
12651268envoyProxy :nil ,
1266- expectedSvcName :proxy .ExpectedResourceHashedName ("merged-gc" ),
1269+ expectedSvcName :proxy .ExpectedResourceHashedName (gcName ),
1270+ serviceCluster : []client.Object {
1271+ & corev1.Service {
1272+ ObjectMeta : metav1.ObjectMeta {
1273+ Name :proxy .ExpectedResourceHashedName (gcName ),
1274+ Namespace :nsName ,
1275+ },
1276+ },
1277+ },
12671278},
12681279{
12691280name :"when merged gateways and a hardcoded svc name is used" ,
12701281gatewayClass :& gwapiv1.GatewayClass {
12711282ObjectMeta : metav1.ObjectMeta {
1272- Name :"merged-gc" ,
1283+ Name :gcName ,
12731284},
12741285},
12751286envoyProxy :& egv1a1.EnvoyProxy {
12761287ObjectMeta : metav1.ObjectMeta {
1277- Name :"merged-gc" ,
1288+ Name :gcName ,
12781289},
12791290Spec : egv1a1.EnvoyProxySpec {
12801291Provider :& egv1a1.EnvoyProxyProvider {
@@ -1288,6 +1299,25 @@ func TestProcessServiceClusterForGatewayClass(t *testing.T) {
12881299},
12891300},
12901301expectedSvcName :"merged-gc-svc" ,
1302+ serviceCluster : []client.Object {
1303+ & corev1.Service {
1304+ ObjectMeta : metav1.ObjectMeta {
1305+ Name :"merged-gc-svc" ,
1306+ Namespace :nsName ,
1307+ },
1308+ },
1309+ },
1310+ },
1311+ {
1312+ name :"non-existent proxy service" ,
1313+ gatewayClass :& gwapiv1.GatewayClass {
1314+ ObjectMeta : metav1.ObjectMeta {
1315+ Name :gcName ,
1316+ },
1317+ },
1318+ envoyProxy :nil ,
1319+ expectedSvcName :proxy .ExpectedResourceHashedName (gcName ),
1320+ serviceCluster :nil ,
12911321},
12921322}
12931323
@@ -1299,6 +1329,10 @@ func TestProcessServiceClusterForGatewayClass(t *testing.T) {
12991329resourceMap := newResourceMapping ()
13001330
13011331r := newGatewayAPIReconciler (logger )
1332+ r .client = fakeclient .NewClientBuilder ().
1333+ WithScheme (envoygateway .GetScheme ()).
1334+ WithObjects (tc .serviceCluster ... ).
1335+ Build ()
13021336r .namespace = "envoy-gateway-system"
13031337
13041338r .processServiceClusterForGatewayClass (tc .envoyProxy ,tc .gatewayClass ,resourceMap )
@@ -1309,8 +1343,12 @@ func TestProcessServiceClusterForGatewayClass(t *testing.T) {
13091343Name :gwapiv1 .ObjectName (tc .expectedSvcName ),
13101344}
13111345key := backendRefKey (& expectedRef )
1312- require .Contains (t ,resourceMap .allAssociatedBackendRefs ,key )
1313- require .Equal (t ,expectedRef ,resourceMap .allAssociatedBackendRefs [key ])
1346+ if tc .serviceCluster != nil {
1347+ require .Contains (t ,resourceMap .allAssociatedBackendRefs ,key )
1348+ require .Equal (t ,expectedRef ,resourceMap .allAssociatedBackendRefs [key ])
1349+ }else {
1350+ require .NotContains (t ,resourceMap .allAssociatedBackendRefs ,key )
1351+ }
13141352})
13151353}
13161354}
@@ -1324,6 +1362,7 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
13241362gatewayNamespacedMode bool
13251363expectedSvcName string
13261364expectedSvcNamespace string
1365+ serviceCluster []client.Object
13271366}{
13281367{
13291368name :"no gateway namespaced mode with no hardcoded service name" ,
@@ -1377,6 +1416,14 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
13771416gatewayNamespacedMode :true ,
13781417expectedSvcName :"my-gateway" ,
13791418expectedSvcNamespace :"app-namespace" ,
1419+ serviceCluster : []client.Object {
1420+ & corev1.Service {
1421+ ObjectMeta : metav1.ObjectMeta {
1422+ Name :"my-gateway" ,
1423+ Namespace :"app-namespace" ,
1424+ },
1425+ },
1426+ },
13801427},
13811428{
13821429name :"gateway namespaced mode with hardcoded service name" ,
@@ -1404,6 +1451,14 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
14041451gatewayNamespacedMode :true ,
14051452expectedSvcName :"my-gateway-svc" ,
14061453expectedSvcNamespace :"app-namespace" ,
1454+ serviceCluster : []client.Object {
1455+ & corev1.Service {
1456+ ObjectMeta : metav1.ObjectMeta {
1457+ Name :"my-gateway-svc" ,
1458+ Namespace :"app-namespace" ,
1459+ },
1460+ },
1461+ },
14071462},
14081463{
14091464name :"no gateway namespaced mode with no hardcoded service name attached gatewayclass" ,
@@ -1443,6 +1498,10 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
14431498resourceMap := newResourceMapping ()
14441499
14451500r := newGatewayAPIReconciler (logger )
1501+ r .client = fakeclient .NewClientBuilder ().
1502+ WithScheme (envoygateway .GetScheme ()).
1503+ WithObjects (tc .serviceCluster ... ).
1504+ Build ()
14461505r .namespace = "envoy-gateway-system"
14471506r .gatewayNamespaceMode = tc .gatewayNamespacedMode
14481507
@@ -1466,8 +1525,12 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
14661525Name :gwapiv1 .ObjectName (tc .expectedSvcName ),
14671526}
14681527key := backendRefKey (& expectedRef )
1469- require .Contains (t ,resourceMap .allAssociatedBackendRefs ,key )
1470- require .Equal (t ,expectedRef ,resourceMap .allAssociatedBackendRefs [key ])
1528+ if tc .serviceCluster != nil {
1529+ require .Contains (t ,resourceMap .allAssociatedBackendRefs ,key )
1530+ require .Equal (t ,expectedRef ,resourceMap .allAssociatedBackendRefs [key ])
1531+ }else {
1532+ require .NotContains (t ,resourceMap .allAssociatedBackendRefs ,key )
1533+ }
14711534})
14721535}
14731536}