sigs.k8s.io/gateway-api@v1.0.0/conformance/tests/mesh-frontend.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 "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 ) 26 27 func init() { 28 ConformanceTests = append(ConformanceTests, MeshFrontend) 29 } 30 31 var MeshFrontend = suite.ConformanceTest{ 32 ShortName: "MeshFrontend", 33 Description: "Mesh rules should only apply to the associated frontend", 34 Features: []suite.SupportedFeature{ 35 suite.SupportMesh, 36 suite.SupportHTTPRoute, 37 suite.SupportHTTPRouteResponseHeaderModification, 38 }, 39 Manifests: []string{"tests/mesh-frontend.yaml"}, 40 Test: func(t *testing.T, s *suite.ConformanceTestSuite) { 41 client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1) 42 v2 := echo.ConnectToApp(t, s, echo.MeshAppEchoV2) 43 cases := []http.ExpectedResponse{ 44 { 45 TestCaseName: "Send to service", 46 Request: http.Request{ 47 Host: "echo-v2", 48 Method: "GET", 49 }, 50 Response: http.Response{ 51 StatusCode: 200, 52 // Make sure the route actually did something 53 Headers: map[string]string{ 54 "X-Header-Set": "set", 55 }, 56 }, 57 Backend: "echo-v2", 58 }, 59 { 60 TestCaseName: "Send to pod IP", 61 Request: http.Request{ 62 Host: v2.Address, 63 Method: "GET", 64 }, 65 Response: http.Response{ 66 StatusCode: 200, 67 AbsentHeaders: []string{"X-Header-Set"}, 68 }, 69 Backend: "echo-v2", 70 }, 71 } 72 for i := range cases { 73 // Declare tc here to avoid loop variable 74 // reuse issues across parallel tests. 75 tc := cases[i] 76 t.Run(tc.GetTestCaseName(i), func(t *testing.T) { 77 client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig) 78 }) 79 } 80 }, 81 }