|
| 1 | +/* |
| 2 | +Copyright 2023 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, HTTPRouteRequestMirror) |
| 31 | +} |
| 32 | + |
| 33 | +var HTTPRouteRequestMirror = suite.ConformanceTest{ |
| 34 | + ShortName: "HTTPRouteRequestMirror", |
| 35 | + Description: "An HTTPRoute with request mirror filter", |
| 36 | + Manifests: []string{"tests/httproute-request-mirror.yaml"}, |
| 37 | + Features: []suite.SupportedFeature{ |
| 38 | + suite.SupportGateway, |
| 39 | + suite.SupportHTTPRoute, |
| 40 | + suite.SupportHTTPRouteRequestMirror, |
| 41 | + }, |
| 42 | + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { |
| 43 | + ns := "gateway-conformance-infra" |
| 44 | + routeNN := types.NamespacedName{Name: "request-mirror", 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 | + |
| 48 | + testCases := []http.ExpectedResponse{ |
| 49 | + { |
| 50 | + Request: http.Request{ |
| 51 | + Path: "/mirror", |
| 52 | + }, |
| 53 | + ExpectedRequest: &http.ExpectedRequest{ |
| 54 | + Request: http.Request{ |
| 55 | + Path: "/mirror", |
| 56 | + }, |
| 57 | + }, |
| 58 | + Backend: "infra-backend-v1", |
| 59 | + MirroredTo: "infra-backend-v2", |
| 60 | + Namespace: ns, |
| 61 | + }, |
| 62 | + } |
| 63 | + for i := range testCases { |
| 64 | + // Declare tc here to avoid loop variable |
| 65 | + // reuse issues across parallel tests. |
| 66 | + tc := testCases[i] |
| 67 | + t.Run(tc.GetTestCaseName(i), func(t *testing.T) { |
| 68 | + t.Parallel() |
| 69 | + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc) |
| 70 | + http.ExpectMirroredRequest(t, suite.Client, suite.Clientset, ns, tc.MirroredTo, tc.Request.Path) |
| 71 | + }) |
| 72 | + } |
| 73 | + }, |
| 74 | +} |
0 commit comments