...
1
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/http"
27 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
28 "sigs.k8s.io/gateway-api/conformance/utils/suite"
29 )
30
31 func init() {
32 ConformanceTests = append(ConformanceTests, HTTPRouteInvalidNonExistentBackendRef)
33 }
34
35 var HTTPRouteInvalidNonExistentBackendRef = suite.ConformanceTest{
36 ShortName: "HTTPRouteInvalidNonExistentBackendRef",
37 Description: "A single HTTPRoute in the gateway-conformance-infra namespace should set a ResolvedRefs status False with reason BackendNotFound and return 500 when binding to a Gateway in the same namespace if the route has a BackendRef Service that does not exist",
38 Features: []suite.SupportedFeature{
39 suite.SupportGateway,
40 suite.SupportHTTPRoute,
41 },
42 Manifests: []string{"tests/httproute-invalid-backendref-nonexistent.yaml"},
43 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
44 routeNN := types.NamespacedName{Name: "invalid-nonexistent-backend-ref", Namespace: "gateway-conformance-infra"}
45 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"}
46
47
48 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
49
50 t.Run("HTTPRoute with only a nonexistent BackendRef has a ResolvedRefs Condition with status False and Reason BackendNotFound", func(t *testing.T) {
51 resolvedRefsCond := metav1.Condition{
52 Type: string(v1.RouteConditionResolvedRefs),
53 Status: metav1.ConditionFalse,
54 Reason: string(v1.RouteReasonBackendNotFound),
55 }
56
57 kubernetes.HTTPRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN, resolvedRefsCond)
58 })
59
60 t.Run("HTTP Request to invalid nonexistent backend receive a 500", func(t *testing.T) {
61 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, http.ExpectedResponse{
62 Request: http.Request{
63 Method: "GET",
64 Path: "/",
65 },
66 Response: http.Response{StatusCode: 500},
67 })
68 })
69 },
70 }
71
View as plain text