1
16
17 package tests
18
19 import (
20 "testing"
21
22 "k8s.io/apimachinery/pkg/types"
23
24 "sigs.k8s.io/gateway-api/conformance/utils/http"
25 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
26 "sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
27 "sigs.k8s.io/gateway-api/conformance/utils/suite"
28 )
29
30 func init() {
31 ConformanceTests = append(ConformanceTests, HTTPRouteRedirectPort)
32 }
33
34 var HTTPRouteRedirectPort = suite.ConformanceTest{
35 ShortName: "HTTPRouteRedirectPort",
36 Description: "An HTTPRoute with a port redirect filter",
37 Manifests: []string{"tests/httproute-redirect-port.yaml"},
38 Features: []suite.SupportedFeature{
39 suite.SupportGateway,
40 suite.SupportHTTPRoute,
41 suite.SupportHTTPRoutePortRedirect,
42 },
43 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
44 ns := "gateway-conformance-infra"
45 routeNN := types.NamespacedName{Name: "redirect-port", Namespace: ns}
46 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
47 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
48 kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
49
50 testCases := []http.ExpectedResponse{
51 {
52 Request: http.Request{
53 Path: "/port",
54 UnfollowRedirect: true,
55 },
56 Response: http.Response{
57 StatusCode: 302,
58 },
59 RedirectRequest: &roundtripper.RedirectRequest{
60 Port: "8083",
61 },
62 Namespace: ns,
63 }, {
64 Request: http.Request{
65 Path: "/port-and-host",
66 UnfollowRedirect: true,
67 },
68 Response: http.Response{
69 StatusCode: 302,
70 },
71 RedirectRequest: &roundtripper.RedirectRequest{
72 Host: "example.org",
73 Port: "8083",
74 },
75 Namespace: ns,
76 }, {
77 Request: http.Request{
78 Path: "/port-and-status",
79 UnfollowRedirect: true,
80 },
81 Response: http.Response{
82 StatusCode: 301,
83 },
84 RedirectRequest: &roundtripper.RedirectRequest{
85 Port: "8083",
86 },
87 Namespace: ns,
88 }, {
89 Request: http.Request{
90 Path: "/port-and-host-and-status",
91 UnfollowRedirect: true,
92 },
93 Response: http.Response{
94 StatusCode: 302,
95 },
96 RedirectRequest: &roundtripper.RedirectRequest{
97 Port: "8083",
98 Host: "example.org",
99 },
100 Namespace: ns,
101 },
102 }
103 for i := range testCases {
104
105
106 tc := testCases[i]
107 t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
108 t.Parallel()
109 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
110 })
111 }
112 },
113 }
114
View as plain text