...

Source file src/sigs.k8s.io/gateway-api/conformance/tests/httproute-disallowed-kind.go

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

     1  /*
     2  Copyright 2022 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  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  	"k8s.io/apimachinery/pkg/types"
    24  
    25  	v1 "sigs.k8s.io/gateway-api/apis/v1"
    26  	"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
    27  	"sigs.k8s.io/gateway-api/conformance/utils/suite"
    28  )
    29  
    30  func init() {
    31  	ConformanceTests = append(ConformanceTests, HTTPRouteDisallowedKind)
    32  }
    33  
    34  var HTTPRouteDisallowedKind = suite.ConformanceTest{
    35  	ShortName:   "HTTPRouteDisallowedKind",
    36  	Description: "A single HTTPRoute in the gateway-conformance-infra namespace should fail to attach to a Gateway with no listeners that allow the HTTPRoute kind",
    37  	Features: []suite.SupportedFeature{
    38  		suite.SupportGateway,
    39  		suite.SupportHTTPRoute,
    40  		suite.SupportTLSRoute,
    41  	},
    42  	Manifests: []string{"tests/httproute-disallowed-kind.yaml"},
    43  	Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
    44  		// This test creates an additional Gateway in the gateway-conformance-infra
    45  		// namespace so we have to wait for it to be ready.
    46  		kubernetes.NamespacesMustBeReady(t, suite.Client, suite.TimeoutConfig, []string{"gateway-conformance-infra"})
    47  
    48  		routeNN := types.NamespacedName{Name: "disallowed-kind", Namespace: "gateway-conformance-infra"}
    49  		gwNN := types.NamespacedName{Name: "tlsroutes-only", Namespace: "gateway-conformance-infra"}
    50  		kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
    51  
    52  		t.Run("Route should not have been accepted with reason NotAllowedByListeners", func(t *testing.T) {
    53  			kubernetes.HTTPRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN, metav1.Condition{
    54  				Type:   string(v1.RouteConditionAccepted),
    55  				Status: metav1.ConditionFalse,
    56  				Reason: string(v1.RouteReasonNotAllowedByListeners),
    57  			})
    58  		})
    59  		t.Run("Route should not have Parents set in status", func(t *testing.T) {
    60  			kubernetes.HTTPRouteMustHaveNoAcceptedParents(t, suite.Client, suite.TimeoutConfig, routeNN)
    61  		})
    62  		t.Run("Gateway should have 0 Routes attached", func(t *testing.T) {
    63  			kubernetes.GatewayMustHaveZeroRoutes(t, suite.Client, suite.TimeoutConfig, gwNN)
    64  		})
    65  	},
    66  }
    67  

View as plain text