sigs.k8s.io/gateway-api@v1.0.0/conformance/tests/httproute-request-multiple-mirrors.go (about) 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, HTTPRouteRequestMultipleMirrors) 31 } 32 33 var HTTPRouteRequestMultipleMirrors = suite.ConformanceTest{ 34 ShortName: "HTTPRouteRequestMultipleMirrors", 35 Description: "An HTTPRoute with multiple request mirror filters", 36 Manifests: []string{"tests/httproute-request-multiple-mirrors.yaml"}, 37 Features: []suite.SupportedFeature{ 38 suite.SupportGateway, 39 suite.SupportHTTPRoute, 40 suite.SupportHTTPRouteRequestMirror, 41 suite.SupportHTTPRouteRequestMultipleMirrors, 42 }, 43 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { 44 ns := "gateway-conformance-infra" 45 routeNN := types.NamespacedName{Name: "request-multiple-mirrors", Namespace: ns} 46 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} 47 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) 48 49 testCases := []http.ExpectedResponse{ 50 { 51 Request: http.Request{ 52 Path: "/multi-mirror", 53 }, 54 ExpectedRequest: &http.ExpectedRequest{ 55 Request: http.Request{ 56 Path: "/multi-mirror", 57 }, 58 }, 59 Backend: "infra-backend-v1", 60 MirroredTo: []http.BackendRef{ 61 { 62 Name: "infra-backend-v2", 63 Namespace: ns, 64 }, 65 { 66 Name: "infra-backend-v3", 67 Namespace: ns, 68 }, 69 }, 70 Namespace: ns, 71 }, { 72 Request: http.Request{ 73 Path: "/multi-mirror-and-modify-request-headers", 74 Headers: map[string]string{ 75 "X-Header-Remove": "remove-val", 76 "X-Header-Add-Append": "append-val-1", 77 }, 78 }, 79 ExpectedRequest: &http.ExpectedRequest{ 80 Request: http.Request{ 81 Path: "/multi-mirror-and-modify-request-headers", 82 Headers: map[string]string{ 83 "X-Header-Add": "header-val-1", 84 "X-Header-Add-Append": "append-val-1,header-val-2", 85 "X-Header-Set": "set-overwrites-values", 86 }, 87 }, 88 AbsentHeaders: []string{"X-Header-Remove"}, 89 }, 90 Namespace: ns, 91 Backend: "infra-backend-v1", 92 MirroredTo: []http.BackendRef{ 93 { 94 Name: "infra-backend-v2", 95 Namespace: ns, 96 }, 97 { 98 Name: "infra-backend-v3", 99 Namespace: ns, 100 }, 101 }, 102 }, 103 } 104 for i := range testCases { 105 // Declare tc here to avoid loop variable 106 // reuse issues across parallel tests. 107 tc := testCases[i] 108 t.Run(tc.GetTestCaseName(i), func(t *testing.T) { 109 t.Parallel() 110 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc) 111 http.ExpectMirroredRequest(t, suite.Client, suite.Clientset, tc.MirroredTo, tc.Request.Path) 112 }) 113 } 114 }, 115 }