sigs.k8s.io/gateway-api@v1.0.0/conformance/tests/httproute-rewrite-path.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, HTTPRouteRewritePath) 31 } 32 33 var HTTPRouteRewritePath = suite.ConformanceTest{ 34 ShortName: "HTTPRouteRewritePath", 35 Description: "An HTTPRoute with path rewrite filter", 36 Manifests: []string{"tests/httproute-rewrite-path.yaml"}, 37 Features: []suite.SupportedFeature{ 38 suite.SupportGateway, 39 suite.SupportHTTPRoute, 40 suite.SupportHTTPRoutePathRewrite, 41 }, 42 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { 43 ns := "gateway-conformance-infra" 44 routeNN := types.NamespacedName{Name: "rewrite-path", 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), routeNN) 47 kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN) 48 49 testCases := []http.ExpectedResponse{ 50 { 51 Request: http.Request{ 52 Path: "/prefix/one/two", 53 }, 54 ExpectedRequest: &http.ExpectedRequest{ 55 Request: http.Request{ 56 Path: "/one/two", 57 }, 58 }, 59 Backend: "infra-backend-v1", 60 Namespace: ns, 61 }, 62 { 63 Request: http.Request{ 64 Path: "/strip-prefix/three", 65 }, 66 ExpectedRequest: &http.ExpectedRequest{ 67 Request: http.Request{ 68 Path: "/three", 69 }, 70 }, 71 Backend: "infra-backend-v1", 72 Namespace: ns, 73 }, 74 { 75 Request: http.Request{ 76 Path: "/strip-prefix", 77 }, 78 ExpectedRequest: &http.ExpectedRequest{ 79 Request: http.Request{ 80 Path: "/", 81 }, 82 }, 83 Backend: "infra-backend-v1", 84 Namespace: ns, 85 }, 86 { 87 Request: http.Request{ 88 Path: "/full/one/two", 89 }, 90 ExpectedRequest: &http.ExpectedRequest{ 91 Request: http.Request{ 92 Path: "/one", 93 }, 94 }, 95 Backend: "infra-backend-v1", 96 Namespace: ns, 97 }, 98 { 99 Request: http.Request{ 100 Path: "/full/rewrite-path-and-modify-headers/test", 101 Headers: map[string]string{ 102 "X-Header-Remove": "remove-val", 103 "X-Header-Add-Append": "append-val-1", 104 "X-Header-Set": "set-val", 105 }, 106 }, 107 ExpectedRequest: &http.ExpectedRequest{ 108 Request: http.Request{ 109 Path: "/test", 110 Headers: map[string]string{ 111 "X-Header-Add": "header-val-1", 112 "X-Header-Add-Append": "append-val-1,header-val-2", 113 "X-Header-Set": "set-overwrites-values", 114 }, 115 }, 116 AbsentHeaders: []string{"X-Header-Remove"}, 117 }, 118 Backend: "infra-backend-v1", 119 Namespace: ns, 120 }, 121 { 122 Request: http.Request{ 123 Path: "/prefix/rewrite-path-and-modify-headers/one", 124 Headers: map[string]string{ 125 "X-Header-Remove": "remove-val", 126 "X-Header-Add-Append": "append-val-1", 127 "X-Header-Set": "set-val", 128 }, 129 }, 130 ExpectedRequest: &http.ExpectedRequest{ 131 Request: http.Request{ 132 Path: "/prefix/one", 133 Headers: map[string]string{ 134 "X-Header-Add": "header-val-1", 135 "X-Header-Add-Append": "append-val-1,header-val-2", 136 "X-Header-Set": "set-overwrites-values", 137 }, 138 }, 139 AbsentHeaders: []string{"X-Header-Remove"}, 140 }, 141 Backend: "infra-backend-v1", 142 Namespace: ns, 143 }, 144 } 145 for i := range testCases { 146 // Declare tc here to avoid loop variable 147 // reuse issues across parallel tests. 148 tc := testCases[i] 149 t.Run(tc.GetTestCaseName(i), func(t *testing.T) { 150 t.Parallel() 151 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc) 152 }) 153 } 154 }, 155 }