sigs.k8s.io/gateway-api@v1.0.0/conformance/tests/httproute-matching-across-routes.go (about) 1 /* 2 Copyright 2022 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package tests 18 19 import ( 20 "testing" 21 22 "k8s.io/apimachinery/pkg/types" 23 24 "sigs.k8s.io/gateway-api/conformance/utils/http" 25 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" 26 "sigs.k8s.io/gateway-api/conformance/utils/suite" 27 ) 28 29 func init() { 30 ConformanceTests = append(ConformanceTests, HTTPRouteMatchingAcrossRoutes) 31 } 32 33 var HTTPRouteMatchingAcrossRoutes = suite.ConformanceTest{ 34 ShortName: "HTTPRouteMatchingAcrossRoutes", 35 Description: "Two HTTPRoutes with path matching for different backends", 36 Features: []suite.SupportedFeature{ 37 suite.SupportGateway, 38 suite.SupportHTTPRoute, 39 }, 40 Manifests: []string{"tests/httproute-matching-across-routes.yaml"}, 41 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { 42 ns := "gateway-conformance-infra" 43 routeNN1 := types.NamespacedName{Name: "matching-part1", Namespace: ns} 44 routeNN2 := types.NamespacedName{Name: "matching-part2", Namespace: ns} 45 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} 46 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN1, routeNN2) 47 kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN1, gwNN) 48 kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN2, gwNN) 49 50 testCases := []http.ExpectedResponse{{ 51 Request: http.Request{ 52 Host: "example.com", 53 Path: "/", 54 }, 55 Backend: "infra-backend-v1", 56 Namespace: ns, 57 }, { 58 Request: http.Request{ 59 Host: "example.com", 60 Path: "/example", 61 }, 62 Backend: "infra-backend-v1", 63 Namespace: ns, 64 }, { 65 Request: http.Request{ 66 Host: "example.net", 67 Path: "/example", 68 }, 69 Backend: "infra-backend-v1", 70 Namespace: ns, 71 }, { 72 Request: http.Request{ 73 Host: "example.com", 74 Path: "/example", 75 Headers: map[string]string{"Version": "one"}, 76 }, 77 Backend: "infra-backend-v1", 78 Namespace: ns, 79 }, { 80 Request: http.Request{ 81 Host: "example.com", 82 Path: "/v2", 83 }, 84 Backend: "infra-backend-v2", 85 Namespace: ns, 86 }, { 87 Request: http.Request{ 88 // v2 matches are limited to example.com 89 Host: "example.net", 90 Path: "/v2", 91 }, 92 Backend: "infra-backend-v1", 93 Namespace: ns, 94 }, { 95 Request: http.Request{ 96 Host: "example.com", 97 Path: "/v2/example", 98 }, 99 Backend: "infra-backend-v2", 100 Namespace: ns, 101 }, { 102 Request: http.Request{ 103 Host: "example.com", 104 Path: "/", 105 Headers: map[string]string{"Version": "two"}, 106 }, 107 Backend: "infra-backend-v2", 108 Namespace: ns, 109 }} 110 111 for i := range testCases { 112 // Declare tc here to avoid loop variable 113 // reuse issues across parallel tests. 114 tc := testCases[i] 115 t.Run(tc.GetTestCaseName(i), func(t *testing.T) { 116 t.Parallel() 117 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc) 118 }) 119 } 120 }, 121 }