@@ -496,6 +496,7 @@ func TestBuildGRPCRoute(t *testing.T) {
496496 expected * L7Route
497497 name string
498498 http2disabled bool
499+ shouldPanic bool
499500 }{
500501 {
501502 validator : createAllValidValidator (),
@@ -726,126 +727,22 @@ func TestBuildGRPCRoute(t *testing.T) {
726727 name : "invalid route with disabled http2" ,
727728 },
728729 {
729- validator : createAllValidValidator (),
730- gr : grOneInvalid ,
731- expected : & L7Route {
732- Source : grOneInvalid ,
733- RouteType : RouteTypeGRPC ,
734- Valid : true ,
735- Attachable : true ,
736- ParentRefs : []ParentRef {
737- {
738- Idx : 0 ,
739- Gateway : gatewayNsName ,
740- SectionName : grOneInvalid .Spec .ParentRefs [0 ].SectionName ,
741- },
742- },
743- Conditions : []conditions.Condition {
744- staticConds .NewRoutePartiallyInvalid (
745- `spec.rules[1].matches[0].headers[0].type: Unsupported value: "": supported values: "Exact", "RegularExpression"` ,
746- ),
747- },
748- Spec : L7RouteSpec {
749- Hostnames : grOneInvalid .Spec .Hostnames ,
750- Rules : []RouteRule {
751- {
752- ValidMatches : true ,
753- Filters : RouteRuleFilters {
754- Valid : true ,
755- Filters : []Filter {},
756- },
757- Matches : ConvertGRPCMatches (grOneInvalid .Spec .Rules [0 ].Matches ),
758- RouteBackendRefs : []RouteBackendRef {},
759- },
760- {
761- ValidMatches : false ,
762- Filters : RouteRuleFilters {
763- Valid : true ,
764- Filters : []Filter {},
765- },
766- Matches : ConvertGRPCMatches (grOneInvalid .Spec .Rules [1 ].Matches ),
767- RouteBackendRefs : []RouteBackendRef {},
768- },
769- },
770- },
771- },
772- name : "invalid headers and valid method" ,
730+ validator : createAllValidValidator (),
731+ gr : grOneInvalid ,
732+ shouldPanic : true ,
733+ name : "invalid headers and valid method" ,
773734 },
774735 {
775- validator : createAllValidValidator (),
776- gr : grInvalidHeadersInvalidType ,
777- expected : & L7Route {
778- Source : grInvalidHeadersInvalidType ,
779- RouteType : RouteTypeGRPC ,
780- Valid : false ,
781- Attachable : true ,
782- ParentRefs : []ParentRef {
783- {
784- Idx : 0 ,
785- Gateway : gatewayNsName ,
786- SectionName : grInvalidHeadersInvalidType .Spec .ParentRefs [0 ].SectionName ,
787- },
788- },
789- Conditions : []conditions.Condition {
790- staticConds .NewRouteUnsupportedValue (
791- `All rules are invalid: spec.rules[0].matches[0].headers[0].type: ` +
792- `Unsupported value: "": supported values: "Exact", "RegularExpression"` ,
793- ),
794- },
795- Spec : L7RouteSpec {
796- Hostnames : grInvalidHeadersInvalidType .Spec .Hostnames ,
797- Rules : []RouteRule {
798- {
799- ValidMatches : false ,
800- Filters : RouteRuleFilters {
801- Valid : true ,
802- Filters : []Filter {},
803- },
804- Matches : ConvertGRPCMatches (grInvalidHeadersInvalidType .Spec .Rules [0 ].Matches ),
805- RouteBackendRefs : []RouteBackendRef {},
806- },
807- },
808- },
809- },
810- name : "invalid headers with invalid type" ,
736+ validator : createAllValidValidator (),
737+ gr : grInvalidHeadersInvalidType ,
738+ shouldPanic : true ,
739+ name : "invalid headers with invalid type" ,
811740 },
812741 {
813- validator : createAllValidValidator (),
814- gr : grInvalidHeadersEmptyType ,
815- expected : & L7Route {
816- Source : grInvalidHeadersEmptyType ,
817- RouteType : RouteTypeGRPC ,
818- Valid : false ,
819- Attachable : true ,
820- ParentRefs : []ParentRef {
821- {
822- Idx : 0 ,
823- Gateway : gatewayNsName ,
824- SectionName : grInvalidHeadersEmptyType .Spec .ParentRefs [0 ].SectionName ,
825- },
826- },
827- Conditions : []conditions.Condition {
828- staticConds .NewRouteUnsupportedValue (
829- `All rules are invalid: spec.rules[0].matches[0].headers[0].type: ` +
830- `Required value: cannot be empty` ,
831- ),
832- },
833- Spec : L7RouteSpec {
834- Hostnames : grInvalidHeadersEmptyType .Spec .Hostnames ,
835- Rules : []RouteRule {
836- {
837- ValidMatches : false ,
838- Filters : RouteRuleFilters {
839- Valid : true ,
840- Filters : []Filter {},
841- },
842- Matches : ConvertGRPCMatches (grInvalidHeadersEmptyType .Spec .Rules [0 ].Matches ),
843- RouteBackendRefs : []RouteBackendRef {},
844- },
845- },
846- },
847- },
848- name : "invalid headers with no header type specified" ,
742+ validator : createAllValidValidator (),
743+ gr : grInvalidHeadersEmptyType ,
744+ shouldPanic : true ,
745+ name : "invalid headers with no header type specified" ,
849746 },
850747 {
851748 validator : createAllValidValidator (),
@@ -988,7 +885,6 @@ func TestBuildGRPCRoute(t *testing.T) {
988885 },
989886 },
990887 },
991-
992888 name : "invalid snippet filter extension ref" ,
993889 },
994890 {
@@ -1028,7 +924,6 @@ func TestBuildGRPCRoute(t *testing.T) {
1028924 },
1029925 },
1030926 },
1031-
1032927 name : "unresolvable snippet filter extension ref" ,
1033928 },
1034929 {
@@ -1072,7 +967,6 @@ func TestBuildGRPCRoute(t *testing.T) {
1072967 },
1073968 },
1074969 },
1075-
1076970 name : "one invalid and one unresolvable snippet filter extension ref" ,
1077971 },
1078972 }
@@ -1088,8 +982,20 @@ func TestBuildGRPCRoute(t *testing.T) {
1088982 {Namespace : "test" , Name : "sf" }: {Valid : true },
1089983 }
1090984
1091- route := buildGRPCRoute (test .validator , test .gr , gatewayNsNames , test .http2disabled , snippetsFilters )
1092- g .Expect (helpers .Diff (test .expected , route )).To (BeEmpty ())
985+ if test .shouldPanic {
986+ g .Expect (func () {
987+ buildGRPCRoute (
988+ test .validator ,
989+ test .gr ,
990+ gatewayNsNames ,
991+ test .http2disabled ,
992+ snippetsFilters ,
993+ )
994+ }).To (Panic ())
995+ } else {
996+ route := buildGRPCRoute (test .validator , test .gr , gatewayNsNames , test .http2disabled , snippetsFilters )
997+ g .Expect (helpers .Diff (test .expected , route )).To (BeEmpty ())
998+ }
1093999 })
10941000 }
10951001}
@@ -1215,10 +1121,6 @@ func TestConvertGRPCHeaderMatchType(t *testing.T) {
12151121 expected : helpers .GetPointer (v1 .HeaderMatchType ("unsupported" )),
12161122 shouldPanic : true ,
12171123 },
1218- {
1219- name : "nil match type" ,
1220- expected : helpers .GetPointer (v1 .HeaderMatchExact ),
1221- },
12221124 }
12231125
12241126 for _ , test := range tests {
0 commit comments