...
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, HTTPRouteRedirectHostAndStatus)
32 }
33
34 var HTTPRouteRedirectHostAndStatus = suite.ConformanceTest{
35 ShortName: "HTTPRouteRedirectHostAndStatus",
36 Description: "An HTTPRoute with hostname and statusCode redirect filters",
37 Features: []suite.SupportedFeature{
38 suite.SupportGateway,
39 suite.SupportHTTPRoute,
40 },
41 Manifests: []string{"tests/httproute-redirect-host-and-status.yaml"},
42 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
43 ns := "gateway-conformance-infra"
44 routeNN := types.NamespacedName{Name: "redirect-host-and-status", Namespace: ns}
45 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
46 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
47 kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
48
49 testCases := []http.ExpectedResponse{
50 {
51 Request: http.Request{
52 Path: "/hostname-redirect",
53 UnfollowRedirect: true,
54 },
55 Response: http.Response{
56 StatusCode: 302,
57 },
58 RedirectRequest: &roundtripper.RedirectRequest{
59 Host: "example.org",
60 },
61 Namespace: ns,
62 }, {
63 Request: http.Request{
64 Path: "/host-and-status",
65 UnfollowRedirect: true,
66 },
67 Response: http.Response{
68 StatusCode: 301,
69 },
70 RedirectRequest: &roundtripper.RedirectRequest{
71 Host: "example.org",
72 },
73 Namespace: ns,
74 },
75 }
76 for i := range testCases {
77
78
79 tc := testCases[i]
80 t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
81 t.Parallel()
82 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
83 })
84 }
85 },
86 }
87
View as plain text