...

Source file src/sigs.k8s.io/gateway-api/conformance/tests/mesh-frontend-hostname.go

Documentation: sigs.k8s.io/gateway-api/conformance/tests

     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, MeshFrontendHostname)
    29  }
    30  
    31  var MeshFrontendHostname = suite.ConformanceTest{
    32  	ShortName:   "MeshFrontendHostname",
    33  	Description: "Mesh parentRef matches Service IP (not Host)",
    34  	Features: []suite.SupportedFeature{
    35  		suite.SupportMesh,
    36  		suite.SupportHTTPRouteResponseHeaderModification,
    37  	},
    38  	Manifests: []string{"tests/mesh-frontend.yaml"},
    39  	Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
    40  		client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)
    41  		cases := []http.ExpectedResponse{
    42  			{
    43  				TestCaseName: "Send to service with wrong hostname",
    44  				Request: http.Request{
    45  					Host: "echo-v2",
    46  					Headers: map[string]string{
    47  						"Host": "echo-v1",
    48  					},
    49  					Method: "GET",
    50  				},
    51  				Response: http.Response{
    52  					StatusCode: 200,
    53  					// Make sure the route actually did something
    54  					Headers: map[string]string{
    55  						"X-Header-Set": "set",
    56  					},
    57  				},
    58  				Backend: "echo-v2",
    59  			},
    60  			{
    61  				TestCaseName: "Send to other service with matching hostname",
    62  				Request: http.Request{
    63  					Host: "echo-v1",
    64  					Headers: map[string]string{
    65  						"Host": "echo-v2",
    66  					},
    67  					Method: "GET",
    68  				},
    69  				Response: http.Response{
    70  					StatusCode:    200,
    71  					AbsentHeaders: []string{"X-Header-Set"},
    72  				},
    73  				Backend: "echo-v1",
    74  			},
    75  		}
    76  		for i := range cases {
    77  			// Declare tc here to avoid loop variable
    78  			// reuse issues across parallel tests.
    79  			tc := cases[i]
    80  			t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
    81  				client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
    82  			})
    83  		}
    84  	},
    85  }
    86  

View as plain text