|
| 1 | +/* |
| 2 | +Copyright 2025 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 meshtests |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "sigs.k8s.io/gateway-api/conformance/utils/echo" |
| 23 | + "sigs.k8s.io/gateway-api/conformance/utils/http" |
| 24 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 25 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 26 | +) |
| 27 | + |
| 28 | +func init() { |
| 29 | + MeshConformanceTests = append(MeshConformanceTests, MeshHTTPRouteRewritePath) |
| 30 | +} |
| 31 | + |
| 32 | +var MeshHTTPRouteRewritePath = suite.ConformanceTest{ |
| 33 | + ShortName: "MeshHTTPRouteRewritePath", |
| 34 | + Description: "An HTTPRoute with path rewrite filter", |
| 35 | + Features: []features.FeatureName{ |
| 36 | + features.SupportMesh, |
| 37 | + features.SupportMeshHTTPRouteRewritePath, |
| 38 | + features.SupportHTTPRoute, |
| 39 | + }, |
| 40 | + Manifests: []string{"tests/mesh/httproute-rewrite-path.yaml"}, |
| 41 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 42 | + ns := "gateway-conformance-mesh" |
| 43 | + client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1) |
| 44 | + cases := []http.ExpectedResponse{ |
| 45 | + { |
| 46 | + Request: http.Request{ |
| 47 | + Path: "/prefix/one/two", |
| 48 | + Host: "echo", |
| 49 | + }, |
| 50 | + ExpectedRequest: &http.ExpectedRequest{ |
| 51 | + Request: http.Request{ |
| 52 | + Path: "/one/two", |
| 53 | + }, |
| 54 | + }, |
| 55 | + Backend: "echo-v1", |
| 56 | + Namespace: ns, |
| 57 | + }, |
| 58 | + { |
| 59 | + Request: http.Request{ |
| 60 | + Path: "/strip-prefix/three", |
| 61 | + Host: "echo", |
| 62 | + }, |
| 63 | + ExpectedRequest: &http.ExpectedRequest{ |
| 64 | + Request: http.Request{ |
| 65 | + Path: "/three", |
| 66 | + }, |
| 67 | + }, |
| 68 | + Backend: "echo-v1", |
| 69 | + Namespace: ns, |
| 70 | + }, |
| 71 | + { |
| 72 | + Request: http.Request{ |
| 73 | + Path: "/strip-prefix", |
| 74 | + Host: "echo", |
| 75 | + }, |
| 76 | + ExpectedRequest: &http.ExpectedRequest{ |
| 77 | + Request: http.Request{ |
| 78 | + Path: "/", |
| 79 | + }, |
| 80 | + }, |
| 81 | + Backend: "echo-v1", |
| 82 | + Namespace: ns, |
| 83 | + }, |
| 84 | + { |
| 85 | + Request: http.Request{ |
| 86 | + Path: "/full/one/two", |
| 87 | + Host: "echo", |
| 88 | + }, |
| 89 | + ExpectedRequest: &http.ExpectedRequest{ |
| 90 | + Request: http.Request{ |
| 91 | + Path: "/one", |
| 92 | + }, |
| 93 | + }, |
| 94 | + Backend: "echo-v1", |
| 95 | + Namespace: ns, |
| 96 | + }, |
| 97 | + { |
| 98 | + Request: http.Request{ |
| 99 | + Host: "echo", |
| 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: "echo-v1", |
| 119 | + Namespace: ns, |
| 120 | + }, |
| 121 | + { |
| 122 | + Request: http.Request{ |
| 123 | + Host: "echo", |
| 124 | + Path: "/prefix/rewrite-path-and-modify-headers/one", |
| 125 | + Headers: map[string]string{ |
| 126 | + "X-Header-Remove": "remove-val", |
| 127 | + "X-Header-Add-Append": "append-val-1", |
| 128 | + "X-Header-Set": "set-val", |
| 129 | + }, |
| 130 | + }, |
| 131 | + ExpectedRequest: &http.ExpectedRequest{ |
| 132 | + Request: http.Request{ |
| 133 | + Path: "/prefix/one", |
| 134 | + Headers: map[string]string{ |
| 135 | + "X-Header-Add": "header-val-1", |
| 136 | + "X-Header-Add-Append": "append-val-1,header-val-2", |
| 137 | + "X-Header-Set": "set-overwrites-values", |
| 138 | + }, |
| 139 | + }, |
| 140 | + AbsentHeaders: []string{"X-Header-Remove"}, |
| 141 | + }, |
| 142 | + Backend: "echo-v1", |
| 143 | + Namespace: ns, |
| 144 | + }, |
| 145 | + } |
| 146 | + for i := range cases { |
| 147 | + // Declare tc here to avoid loop variable |
| 148 | + // reuse issues across parallel tests. |
| 149 | + tc := cases[i] |
| 150 | + t.Run(tc.GetTestCaseName(i), func(t *testing.T) { |
| 151 | + client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig) |
| 152 | + }) |
| 153 | + } |
| 154 | + }, |
| 155 | +} |
0 commit comments