|
| 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 | +package basic |
| 18 | + |
| 19 | +import ( |
| 20 | + "net/http" |
| 21 | + "testing" |
| 22 | + |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | + "k8s.io/apimachinery/pkg/types" |
| 25 | + "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" |
| 26 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 27 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 28 | + |
| 29 | + "sigs.k8s.io/gateway-api-inference-extension/conformance/tests" |
| 30 | + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" |
| 31 | + conformancehttp "sigs.k8s.io/gateway-api/conformance/utils/http" |
| 32 | +) |
| 33 | + |
| 34 | +func init() { |
| 35 | + tests.ConformanceTests = append(tests.ConformanceTests, InferencePoolInvalidEPPService) |
| 36 | +} |
| 37 | + |
| 38 | +var InferencePoolInvalidEPPService = suite.ConformanceTest{ |
| 39 | + ShortName: "InferencePoolInvalidEPPService", |
| 40 | + Description: "An HTTPRoute that references an InferencePool with a non-existent EPP service should have a ResolvedRefs condition with a status of False and a reason of BackendNotFound.", |
| 41 | + Manifests: []string{"tests/basic/inferencepool_invalid_epp_service.yaml"}, |
| 42 | + Features: []features.FeatureName{ |
| 43 | + features.SupportGateway, |
| 44 | + features.SupportHTTPRoute, |
| 45 | + features.FeatureName("SupportInferencePool"), |
| 46 | + }, |
| 47 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 48 | + const ( |
| 49 | + routePath = "/invalid-epp-test" |
| 50 | + infraNamespace = "gateway-conformance-infra" |
| 51 | + appNamespace = "gateway-conformance-app-backend" |
| 52 | + ) |
| 53 | + |
| 54 | + routeNN := types.NamespacedName{Name: "httproute-for-invalid-epp-pool", Namespace: appNamespace} |
| 55 | + gwNN := types.NamespacedName{Name: "conformance-gateway", Namespace: infraNamespace} |
| 56 | + |
| 57 | + gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, s.Client, s.TimeoutConfig, s.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) |
| 58 | + |
| 59 | + t.Run("HTTPRoute has a ResolvedRefs Condition with status False and Reason BackendNotFound", func(t *testing.T) { |
| 60 | + resolvedRefsCond := metav1.Condition{ |
| 61 | + Type: string(gatewayv1.RouteConditionResolvedRefs), |
| 62 | + Status: metav1.ConditionFalse, |
| 63 | + Reason: string(gatewayv1.RouteReasonBackendNotFound), |
| 64 | + } |
| 65 | + kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, routeNN, gwNN, resolvedRefsCond) |
| 66 | + }) |
| 67 | + |
| 68 | + t.Run("Request to a route with an invalid backend reference receives a 500 response", func(t *testing.T) { |
| 69 | + conformancehttp.MakeRequestAndExpectEventuallyConsistentResponse(t, s.RoundTripper, s.TimeoutConfig, gwAddr, conformancehttp.ExpectedResponse{ |
| 70 | + Request: conformancehttp.Request{ |
| 71 | + Path: routePath, |
| 72 | + }, |
| 73 | + Response: conformancehttp.Response{ |
| 74 | + StatusCode: http.StatusInternalServerError, |
| 75 | + }, |
| 76 | + }) |
| 77 | + }) |
| 78 | + }, |
| 79 | +} |
0 commit comments