From 94278ae67c52ddb15e783eea99da72fccaf18a69 Mon Sep 17 00:00:00 2001 From: David Winiarski Date: Sun, 6 Apr 2025 18:43:44 -0600 Subject: [PATCH] update all route tests to have a valid spec.parentRef entry --- source/gateway_grpcroute_test.go | 5 + source/gateway_httproute_test.go | 261 ++++++++++++++++++++++++++++++- source/gateway_tcproute_test.go | 8 +- source/gateway_test.go | 73 --------- source/gateway_tlsroute_test.go | 5 + source/gateway_udproute_test.go | 8 +- 6 files changed, 284 insertions(+), 76 deletions(-) diff --git a/source/gateway_grpcroute_test.go b/source/gateway_grpcroute_test.go index f92070eb4..a794c3796 100644 --- a/source/gateway_grpcroute_test.go +++ b/source/gateway_grpcroute_test.go @@ -74,6 +74,11 @@ func TestGatewayGRPCRouteSourceEndpoints(t *testing.T) { }, Spec: v1.GRPCRouteSpec{ Hostnames: []v1.Hostname{"api-hostnames.foobar.internal"}, + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "internal"), + }, + }, }, Status: v1.GRPCRouteStatus{ RouteStatus: gwRouteStatus(gwParentRef("default", "internal")), diff --git a/source/gateway_httproute_test.go b/source/gateway_httproute_test.go index 629a9e581..a09f25bc4 100644 --- a/source/gateway_httproute_test.go +++ b/source/gateway_httproute_test.go @@ -174,6 +174,12 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("route-namespace", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("test.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("gateway-namespace", "gateway-name"), + gwParentRef("gateway-namespace", "not-gateway-name"), + }, + }, }, Status: httpRouteStatus( // The route is attached to both gateways. gwParentRef("gateway-namespace", "gateway-name"), @@ -216,6 +222,12 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("route-namespace", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("test.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("gateway-namespace", "test"), + gwParentRef("not-gateway-namespace", "test"), + }, + }, }, Status: httpRouteStatus( // The route is attached to both gateways. gwParentRef("gateway-namespace", "test"), @@ -247,6 +259,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("route-namespace", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("route-namespace.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("gateway-namespace", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("gateway-namespace", "test")), }, @@ -296,6 +313,12 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("test.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "labels-match"), + gwParentRef("default", "labels-dont-match"), + }, + }, }, Status: httpRouteStatus( // The route is attached to both gateways. gwParentRef("default", "labels-match"), @@ -328,6 +351,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("labels-match.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, @@ -339,6 +367,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("labels-dont-match.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, @@ -369,6 +402,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("annotations-match.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, @@ -380,6 +418,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("annotations-dont-match.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, @@ -408,6 +451,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, }, Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: hostnames("api.example.internal"), }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -438,6 +486,12 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("test.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "one"), + gwParentRef("default", "two"), + }, + }, }, Status: httpRouteStatus( gwParentRef("default", "one"), @@ -474,6 +528,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("*.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "one"), + }, + }, }, Status: httpRouteStatus( gwParentRef("default", "one"), @@ -510,6 +569,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("*.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test", withSectionName("foo")), + }, + }, }, Status: httpRouteStatus( gwParentRef("default", "test", withSectionName("foo")), @@ -554,6 +618,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("*.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test", withPortNumber(80)), + }, + }, }, Status: httpRouteStatus( gwParentRef("default", "test", withPortNumber(80)), @@ -581,6 +650,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { routes: []*v1beta1.HTTPRoute{{ ObjectMeta: objectMeta("default", "no-hostname"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: []v1.Hostname{ "foo.example.internal", }, @@ -608,6 +682,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { routes: []*v1beta1.HTTPRoute{{ ObjectMeta: objectMeta("default", "no-hostname"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: []v1.Hostname{ "*.example.internal", }, @@ -635,6 +714,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { routes: []*v1beta1.HTTPRoute{{ ObjectMeta: objectMeta("default", "no-hostname"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: []v1.Hostname{ "*.example.internal", }, @@ -662,6 +746,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { routes: []*v1beta1.HTTPRoute{{ ObjectMeta: objectMeta("default", "no-hostname"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: nil, }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -679,6 +768,9 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{}, + }, }, Status: httpRouteStatus(), }}, @@ -698,6 +790,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { routes: []*v1beta1.HTTPRoute{{ ObjectMeta: objectMeta("default", "no-hostname"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: nil, }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -725,6 +822,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, }, Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: nil, }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -738,6 +840,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, }, Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: hostnames("with-hostname.internal"), }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -772,6 +879,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("with-hostname.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }}, @@ -797,12 +909,22 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "fqdn-with-hostnames"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("fqdn-with-hostnames.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, { ObjectMeta: objectMeta("default", "fqdn-without-hostnames"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: nil, }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -832,6 +954,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { routes: []*v1beta1.HTTPRoute{{ ObjectMeta: objectMeta("default", "fqdn-with-hostnames"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: hostnames("fqdn-with-hostnames.internal"), }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -861,6 +988,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("valid-ttl.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, @@ -872,6 +1004,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("invalid-ttl.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, @@ -902,6 +1039,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { }, }, Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: hostnames("provider-annotations.com"), }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -941,6 +1083,12 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { routes: []*v1beta1.HTTPRoute{{ ObjectMeta: objectMeta("default", "test"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "one"), + gwParentRef("default", "two"), + }, + }, Hostnames: hostnames("test.one.internal", "test.two.internal"), }, Status: httpRouteStatus( @@ -976,6 +1124,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("same-namespace", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("same-namespace.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("same-namespace", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("same-namespace", "test")), }, @@ -983,6 +1136,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("other-namespace", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("other-namespace.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("same-namespace", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("same-namespace", "test")), }, @@ -1035,6 +1193,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("foo", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("foo.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, @@ -1042,6 +1205,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("bar", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("bar.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, }, Status: httpRouteStatus(gwParentRef("default", "test")), }, @@ -1075,6 +1243,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { routes: []*v1beta1.HTTPRoute{{ ObjectMeta: objectMeta("default", "test"), Spec: v1.HTTPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "test"), + }, + }, Hostnames: hostnames("example.internal"), }, Status: httpRouteStatus(gwParentRef("default", "test")), @@ -1109,6 +1282,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("route-namespace", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("test.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("gateway-namespace", "overriden-gateway"), + }, + }, }, Status: httpRouteStatus( // The route is attached to both gateways. gwParentRef("gateway-namespace", "overriden-gateway"), @@ -1156,8 +1334,14 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("route-namespace", "test"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("test.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("gateway-namespace", "overriden-gateway"), + gwParentRef("gateway-namespace", "test"), + }, + }, }, - Status: httpRouteStatus( // The route is attached to both gateways. + Status: httpRouteStatus( gwParentRef("gateway-namespace", "overriden-gateway"), gwParentRef("gateway-namespace", "test"), ), @@ -1191,6 +1375,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "one"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("test.one.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "one"), + }, + }, }, Status: httpRouteStatus( gwParentRef("default", "one"), @@ -1200,6 +1389,11 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: objectMeta("default", "two"), Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("test.two.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "two"), + }, + }, }, Status: httpRouteStatus( gwParentRef("default", "two"), @@ -1215,6 +1409,71 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { "level=debug msg=\"Endpoints generated from HTTPRoute default/two: [test.two.internal 0 IN A 2.3.4.5 []]\"", }, }, + { + title: "NoParentRefs", + config: Config{ + GatewayNamespace: "gateway-namespace", + }, + namespaces: namespaces("gateway-namespace", "route-namespace"), + gateways: []*v1beta1.Gateway{ + { + ObjectMeta: objectMeta("gateway-namespace", "test"), + Spec: v1.GatewaySpec{ + Listeners: []v1.Listener{{ + Protocol: v1.HTTPProtocolType, + AllowedRoutes: allowAllNamespaces, + }}, + }, + Status: gatewayStatus("1.2.3.4"), + }, + }, + routes: []*v1beta1.HTTPRoute{{ + ObjectMeta: objectMeta("route-namespace", "test"), + Spec: v1.HTTPRouteSpec{ + Hostnames: hostnames("test.example.internal"), + }, + Status: httpRouteStatus(gwParentRef("gateway-namespace", "test")), + }}, + endpoints: []*endpoint.Endpoint{}, + logExpectations: []string{ + "level=debug msg=\"No parent references found for HTTPRoute route-namespace/test\"", + }, + }, + { + title: "ParentRefsMismatch", + config: Config{ + GatewayNamespace: "gateway-namespace", + }, + namespaces: namespaces("gateway-namespace", "route-namespace"), + gateways: []*v1beta1.Gateway{ + { + ObjectMeta: objectMeta("gateway-namespace", "test"), + Spec: v1.GatewaySpec{ + Listeners: []v1.Listener{{ + Protocol: v1.HTTPProtocolType, + AllowedRoutes: allowAllNamespaces, + }}, + }, + Status: gatewayStatus("1.2.3.4"), + }, + }, + routes: []*v1beta1.HTTPRoute{{ + ObjectMeta: objectMeta("route-namespace", "test"), + Spec: v1.HTTPRouteSpec{ + Hostnames: hostnames("test.example.internal"), + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("gateway-namespace", "default-gateway"), + }, + }, + }, + Status: httpRouteStatus(gwParentRef("gateway-namespace", "other-gateway")), + }}, + endpoints: []*endpoint.Endpoint{}, + logExpectations: []string{ + "level=debug msg=\"Parent reference gateway-namespace/other-gateway not found in routeParentRefs for HTTPRoute route-namespace/test\"", + }, + }, } for _, tt := range tests { tt := tt diff --git a/source/gateway_tcproute_test.go b/source/gateway_tcproute_test.go index a6039ebf1..417ac788b 100644 --- a/source/gateway_tcproute_test.go +++ b/source/gateway_tcproute_test.go @@ -73,7 +73,13 @@ func TestGatewayTCPRouteSourceEndpoints(t *testing.T) { hostnameAnnotationKey: "api-annotation.foobar.internal", }, }, - Spec: v1alpha2.TCPRouteSpec{}, + Spec: v1alpha2.TCPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "internal"), + }, + }, + }, Status: v1alpha2.TCPRouteStatus{ RouteStatus: gwRouteStatus(gwParentRef("default", "internal")), }, diff --git a/source/gateway_test.go b/source/gateway_test.go index 92e71a91f..940622e95 100644 --- a/source/gateway_test.go +++ b/source/gateway_test.go @@ -20,7 +20,6 @@ import ( "strings" "testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "sigs.k8s.io/gateway-api/apis/v1" ) @@ -246,75 +245,3 @@ func TestIsDNS1123Domain(t *testing.T) { }) } } - -func TestGwRouteIsAccepted(t *testing.T) { - tests := []struct { - desc string - conditions []metav1.Condition - currentGeneration int64 - want bool - }{ - { - desc: "accepted condition with matching generation", - conditions: []metav1.Condition{ - { - Type: string(v1.RouteConditionAccepted), - Status: metav1.ConditionTrue, - ObservedGeneration: 1, - }, - }, - currentGeneration: 1, - want: true, - }, - { - desc: "accepted condition with different generation", - conditions: []metav1.Condition{ - { - Type: string(v1.RouteConditionAccepted), - Status: metav1.ConditionTrue, - ObservedGeneration: 1, - }, - }, - currentGeneration: 2, - want: false, - }, - { - desc: "accepted condition with false status", - conditions: []metav1.Condition{ - { - Type: string(v1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - ObservedGeneration: 1, - }, - }, - currentGeneration: 1, - want: false, - }, - { - desc: "no accepted condition", - conditions: []metav1.Condition{ - { - Type: "OtherCondition", - Status: metav1.ConditionTrue, - ObservedGeneration: 1, - }, - }, - currentGeneration: 1, - want: false, - }, - { - desc: "empty conditions", - conditions: []metav1.Condition{}, - currentGeneration: 1, - want: false, - }, - } - - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if got := gwRouteIsAccepted(tt.conditions, tt.currentGeneration); got != tt.want { - t.Errorf("gwRouteIsAccepted() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/source/gateway_tlsroute_test.go b/source/gateway_tlsroute_test.go index e6d4660e5..238b62598 100644 --- a/source/gateway_tlsroute_test.go +++ b/source/gateway_tlsroute_test.go @@ -75,6 +75,11 @@ func TestGatewayTLSRouteSourceEndpoints(t *testing.T) { }, Spec: v1alpha2.TLSRouteSpec{ Hostnames: []v1.Hostname{"api-hostnames.foobar.internal"}, + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "internal"), + }, + }, }, Status: v1alpha2.TLSRouteStatus{ RouteStatus: gwRouteStatus(gwParentRef("default", "internal")), diff --git a/source/gateway_udproute_test.go b/source/gateway_udproute_test.go index 570e3d10c..161de45f4 100644 --- a/source/gateway_udproute_test.go +++ b/source/gateway_udproute_test.go @@ -73,7 +73,13 @@ func TestGatewayUDPRouteSourceEndpoints(t *testing.T) { hostnameAnnotationKey: "api-annotation.foobar.internal", }, }, - Spec: v1alpha2.UDPRouteSpec{}, + Spec: v1alpha2.UDPRouteSpec{ + CommonRouteSpec: v1.CommonRouteSpec{ + ParentRefs: []v1.ParentReference{ + gwParentRef("default", "internal"), + }, + }, + }, Status: v1alpha2.UDPRouteStatus{ RouteStatus: gwRouteStatus(gwParentRef("default", "internal")), },