...

Source file src/sigs.k8s.io/gateway-api/conformance/tests/mesh-ports.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, MeshPorts)
    29  }
    30  
    31  var MeshPorts = suite.ConformanceTest{
    32  	ShortName:   "MeshPorts",
    33  	Description: "A mesh route can optionally configure 'port' in parentRef",
    34  	Features: []suite.SupportedFeature{
    35  		suite.SupportMesh,
    36  		suite.SupportHTTPRoute,
    37  		suite.SupportHTTPRouteResponseHeaderModification,
    38  	},
    39  	Manifests: []string{"tests/mesh-ports.yaml"},
    40  	Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
    41  		client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)
    42  		cases := []http.ExpectedResponse{
    43  			{
    44  				TestCaseName: "Explicit port set, send to that port",
    45  				Request: http.Request{
    46  					Host:   "echo-v1",
    47  					Method: "GET",
    48  				},
    49  				Response: http.Response{
    50  					StatusCode: 200,
    51  					// Make sure the route actually did something
    52  					Headers: map[string]string{
    53  						"X-Header-Set": "v1",
    54  					},
    55  				},
    56  				Backend: "echo-v1",
    57  			},
    58  			{
    59  				TestCaseName: "Explicit port, send to an excluded port",
    60  				Request: http.Request{
    61  					Host:   "echo-v1:8080",
    62  					Method: "GET",
    63  				},
    64  				Response: http.Response{
    65  					StatusCode: 200,
    66  					// Route should not apply
    67  					AbsentHeaders: []string{"X-Header-Set"},
    68  				},
    69  				Backend: "echo-v1",
    70  			},
    71  			{
    72  				TestCaseName: "No port set",
    73  				Request: http.Request{
    74  					Host:   "echo-v2",
    75  					Method: "GET",
    76  				},
    77  				Response: http.Response{
    78  					StatusCode: 200,
    79  					Headers: map[string]string{
    80  						"X-Header-Set": "v2",
    81  					},
    82  				},
    83  				Backend: "echo-v2",
    84  			},
    85  			{
    86  				TestCaseName: "No port set",
    87  				Request: http.Request{
    88  					Host:   "echo-v2:8080",
    89  					Method: "GET",
    90  				},
    91  				Response: http.Response{
    92  					StatusCode: 200,
    93  					Headers: map[string]string{
    94  						"X-Header-Set": "v2",
    95  					},
    96  				},
    97  				Backend: "echo-v2",
    98  			},
    99  		}
   100  		for i := range cases {
   101  			// Declare tc here to avoid loop variable
   102  			// reuse issues across parallel tests.
   103  			tc := cases[i]
   104  			t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
   105  				client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
   106  			})
   107  		}
   108  	},
   109  }
   110  

View as plain text