1
16
17 package tests
18
19 import (
20 "context"
21 "testing"
22
23 "github.com/stretchr/testify/require"
24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25 "k8s.io/apimachinery/pkg/types"
26
27 v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
28 "sigs.k8s.io/gateway-api/conformance/utils/http"
29 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
30 "sigs.k8s.io/gateway-api/conformance/utils/suite"
31 )
32
33 func init() {
34 ConformanceTests = append(ConformanceTests, HTTPRouteReferenceGrant)
35 }
36
37 var HTTPRouteReferenceGrant = suite.ConformanceTest{
38 ShortName: "HTTPRouteReferenceGrant",
39 Description: "A single HTTPRoute in the gateway-conformance-infra namespace, with a backendRef in the gateway-conformance-web-backend namespace, should attach to Gateway in the gateway-conformance-infra namespace",
40 Features: []suite.SupportedFeature{
41 suite.SupportGateway,
42 suite.SupportHTTPRoute,
43 suite.SupportReferenceGrant,
44 },
45 Manifests: []string{"tests/httproute-reference-grant.yaml"},
46 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
47 routeNN := types.NamespacedName{Name: "reference-grant", Namespace: "gateway-conformance-infra"}
48 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"}
49 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
50 kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
51
52 t.Run("Simple HTTP request should reach web-backend", func(t *testing.T) {
53 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, http.ExpectedResponse{
54 Request: http.Request{
55 Method: "GET",
56 Path: "/",
57 },
58 Response: http.Response{StatusCode: 200},
59 Backend: "web-backend",
60 Namespace: "gateway-conformance-web-backend",
61 })
62 })
63
64 ctx, cancel := context.WithTimeout(context.Background(), suite.TimeoutConfig.DeleteTimeout)
65 defer cancel()
66 rg := v1beta1.ReferenceGrant{
67 ObjectMeta: metav1.ObjectMeta{
68 Name: "reference-grant",
69 Namespace: "gateway-conformance-web-backend",
70 },
71 }
72 require.NoError(t, suite.Client.Delete(ctx, &rg))
73
74 t.Run("Simple HTTP request should return 500 after deleting the relevant reference grant", func(t *testing.T) {
75 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, http.ExpectedResponse{
76 Request: http.Request{
77 Method: "GET",
78 Path: "/",
79 },
80 Response: http.Response{StatusCode: 500},
81 })
82 })
83 },
84 }
85
View as plain text