...

Source file src/sigs.k8s.io/gateway-api/conformance/tests/httproute-path-match-order.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  	"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, HTTPRoutePathMatchOrder)
    31  }
    32  
    33  var HTTPRoutePathMatchOrder = suite.ConformanceTest{
    34  	ShortName:   "HTTPRoutePathMatchOrder",
    35  	Description: "An HTTPRoute where there are multiple matches routing to any given backend follows match order precedence",
    36  	Features: []suite.SupportedFeature{
    37  		suite.SupportGateway,
    38  		suite.SupportHTTPRoute,
    39  	},
    40  	Manifests: []string{"tests/httproute-path-match-order.yaml"},
    41  	Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
    42  		ns := "gateway-conformance-infra"
    43  		routeNN := types.NamespacedName{Namespace: ns, Name: "path-matching-order"}
    44  		gwNN := types.NamespacedName{Namespace: ns, Name: "same-namespace"}
    45  		gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
    46  		kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
    47  
    48  		testCases := []http.ExpectedResponse{
    49  			{
    50  				Request:   http.Request{Path: "/match/exact/one"},
    51  				Backend:   "infra-backend-v3",
    52  				Namespace: ns,
    53  			}, {
    54  				Request:   http.Request{Path: "/match/exact"},
    55  				Backend:   "infra-backend-v2",
    56  				Namespace: ns,
    57  			}, {
    58  				Request:   http.Request{Path: "/match"},
    59  				Backend:   "infra-backend-v1",
    60  				Namespace: ns,
    61  			}, {
    62  				Request:   http.Request{Path: "/match/prefix/one/any"},
    63  				Backend:   "infra-backend-v2",
    64  				Namespace: ns,
    65  			}, {
    66  				Request:   http.Request{Path: "/match/prefix/any"},
    67  				Backend:   "infra-backend-v1",
    68  				Namespace: ns,
    69  			}, {
    70  				Request:   http.Request{Path: "/match/any"},
    71  				Backend:   "infra-backend-v3",
    72  				Namespace: ns,
    73  			},
    74  		}
    75  
    76  		for i := range testCases {
    77  			tc := testCases[i]
    78  			t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
    79  				t.Parallel()
    80  				http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
    81  			})
    82  		}
    83  	},
    84  }
    85  

View as plain text