@@ -216,6 +216,110 @@ func TestProjectedSnapshotKeepsHTTPRouteWithPortQualifiedBackendName(t *testing.
216216 }
217217}
218218
219+ func TestProjectedSnapshotFiltersRouteLocalPortQualifiedBackendRefs (t * testing.T ) {
220+ t .Parallel ()
221+
222+ tests := []struct {
223+ name string
224+ backendRef ir.BackendRef
225+ backends []ir.BackendCluster
226+ wantRoute bool
227+ wantValidFlag string
228+ }{
229+ {
230+ name : "route-local port-qualified backend survives" ,
231+ backendRef : ir.BackendRef {
232+ Name : "orders" ,
233+ Port : 8080 ,
234+ },
235+ backends : []ir.BackendCluster {{
236+ Name : "orders:8080" ,
237+ Namespace : "apps" ,
238+ Protocol : "HTTP" ,
239+ ConnectTimeout : 5 * time .Second ,
240+ Endpoints : []ir.BackendEndpoint {{
241+ Address : "10.0.0.20" ,
242+ Port : 8080 ,
243+ Healthy : true ,
244+ }},
245+ }},
246+ wantRoute : true ,
247+ },
248+ {
249+ name : "wrong port is pruned" ,
250+ backendRef : ir.BackendRef {
251+ Name : "orders" ,
252+ Port : 8081 ,
253+ },
254+ backends : []ir.BackendCluster {{
255+ Name : "orders:8080" ,
256+ Namespace : "apps" ,
257+ Protocol : "HTTP" ,
258+ ConnectTimeout : 5 * time .Second ,
259+ Endpoints : []ir.BackendEndpoint {{
260+ Address : "10.0.0.20" ,
261+ Port : 8080 ,
262+ Healthy : true ,
263+ }},
264+ }},
265+ wantRoute : false ,
266+ },
267+ {
268+ name : "invalid route-local backend ref is preserved" ,
269+ backendRef : ir.BackendRef {
270+ Name : "missing" ,
271+ Port : 8080 ,
272+ Metadata : map [string ]string {
273+ backendRefValidityMetadataKey : "false" ,
274+ },
275+ },
276+ wantRoute : true ,
277+ wantValidFlag : "false" ,
278+ },
279+ }
280+
281+ for _ , tt := range tests {
282+ t .Run (tt .name , func (t * testing.T ) {
283+ t .Parallel ()
284+
285+ projected := buildProjectedProtoSnapshot (
286+ & ir.Snapshot {
287+ HTTPRoutes : []ir.HTTPRoute {{
288+ Name : "orders-route" ,
289+ Namespace : "apps" ,
290+ Rules : []ir.HTTPRule {{
291+ Name : "orders" ,
292+ BackendRefs : []ir.BackendRef {tt .backendRef },
293+ }},
294+ }},
295+ Backends : tt .backends ,
296+ },
297+ effectiveProjectionProfile ([]string {featureCoreV1 }),
298+ slog .New (slog .NewTextHandler (io .Discard , nil )),
299+ )
300+
301+ if ! tt .wantRoute {
302+ if hasProjectedHTTPRoute (projected , "orders-route" ) {
303+ t .Fatalf ("projected route unexpectedly survived: %#v" , projected .GetHttpRoutes ())
304+ }
305+ return
306+ }
307+
308+ route := findProjectedHTTPRoute (t , projected , "orders-route" )
309+ if got := len (route .GetRules ()); got != 1 {
310+ t .Fatalf ("http route rule count = %d, want 1" , got )
311+ }
312+ refs := route .GetRules ()[0 ].GetBackendRefs ()
313+ if got := len (refs ); got != 1 {
314+ t .Fatalf ("http route backend ref count = %d, want 1" , got )
315+ }
316+ if got := refs [0 ].GetMetadata ()[backendRefValidityMetadataKey ]; got != tt .wantValidFlag {
317+ t .Fatalf ("backend ref validity metadata = %q, want %q" , got , tt .wantValidFlag )
318+ }
319+ })
320+ }
321+ }
322+
219323func TestProjectedSnapshotKeepsSecondListenerSetHTTPRoutingRoutes (t * testing.T ) {
220324 t .Parallel ()
221325
0 commit comments