|
| 1 | +/* |
| 2 | +Copyright 2025 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 | +// TODO(#864) refactor the structure to put all tests directly under tests instead of creating subfolders. |
| 18 | +package basic |
| 19 | + |
| 20 | +import ( |
| 21 | + "testing" |
| 22 | + |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | + "k8s.io/apimachinery/pkg/types" |
| 25 | + gatewayv1 "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 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 29 | + |
| 30 | + "sigs.k8s.io/gateway-api-inference-extension/conformance/tests" |
| 31 | +) |
| 32 | + |
| 33 | +func init() { |
| 34 | + tests.ConformanceTests = append(tests.ConformanceTests, HTTPRouteInvalidInferencePoolRef) |
| 35 | +} |
| 36 | + |
| 37 | +var HTTPRouteInvalidInferencePoolRef = suite.ConformanceTest{ |
| 38 | + ShortName: "HTTPRouteInvalidInferencePoolRef", |
| 39 | + Description: "Tests HTTPRoute status when it references an InferencePool that does not exist.", |
| 40 | + Manifests: []string{"tests/basic/httproute_invalid_inferencepool_ref.yaml"}, |
| 41 | + Features: []features.FeatureName{ |
| 42 | + features.FeatureName("SupportInferencePool"), |
| 43 | + features.SupportGateway, |
| 44 | + }, |
| 45 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 46 | + const ( |
| 47 | + appBackendNamespace = "gateway-conformance-app-backend" |
| 48 | + infraNamespace = "gateway-conformance-infra" |
| 49 | + routeName = "httproute-to-non-existent-pool" |
| 50 | + gatewayName = "conformance-gateway" |
| 51 | + ) |
| 52 | + routeNN := types.NamespacedName{Name: routeName, Namespace: appBackendNamespace} |
| 53 | + gatewayNN := types.NamespacedName{Name: gatewayName, Namespace: infraNamespace} |
| 54 | + |
| 55 | + t.Run("HTTPRoute should have Accepted=True and ResolvedRefs=False for non-existent InferencePool", func(t *testing.T) { |
| 56 | + acceptedCondition := metav1.Condition{ |
| 57 | + Type: string(gatewayv1.RouteConditionAccepted), |
| 58 | + Status: metav1.ConditionTrue, |
| 59 | + Reason: string(gatewayv1.RouteReasonAccepted), |
| 60 | + } |
| 61 | + kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN, acceptedCondition) |
| 62 | + |
| 63 | + resolvedRefsCondition := metav1.Condition{ |
| 64 | + Type: string(gatewayv1.RouteConditionResolvedRefs), |
| 65 | + Status: metav1.ConditionFalse, |
| 66 | + Reason: string(gatewayv1.RouteReasonBackendNotFound), |
| 67 | + } |
| 68 | + kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN, resolvedRefsCondition) |
| 69 | + |
| 70 | + t.Logf("Successfully verified HTTPRoute %s has conditions: Accepted=True and ResolvedRefs=False (Reason: BackendNotFound) for Gateway %s", |
| 71 | + routeNN.String(), gatewayNN.String()) |
| 72 | + }) |
| 73 | + }, |
| 74 | +} |
0 commit comments