sigs.k8s.io/gateway-api@v1.0.0/conformance/tests/httproute-redirect-path.go (about) 1 /* 2 Copyright 2022 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 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, HTTPRouteRedirectPath) 32 } 33 34 var HTTPRouteRedirectPath = suite.ConformanceTest{ 35 ShortName: "HTTPRouteRedirectPath", 36 Description: "An HTTPRoute with scheme redirect filter", 37 Manifests: []string{"tests/httproute-redirect-path.yaml"}, 38 Features: []suite.SupportedFeature{ 39 suite.SupportGateway, 40 suite.SupportHTTPRoute, 41 suite.SupportHTTPRoutePathRedirect, 42 }, 43 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { 44 ns := "gateway-conformance-infra" 45 routeNN := types.NamespacedName{Name: "redirect-path", 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: "/original-prefix/lemon", 54 UnfollowRedirect: true, 55 }, 56 Response: http.Response{ 57 StatusCode: 302, 58 }, 59 RedirectRequest: &roundtripper.RedirectRequest{ 60 Path: "/replacement-prefix/lemon", 61 }, 62 Namespace: ns, 63 }, { 64 Request: http.Request{ 65 Path: "/full/path/original", 66 UnfollowRedirect: true, 67 }, 68 Response: http.Response{ 69 StatusCode: 302, 70 }, 71 RedirectRequest: &roundtripper.RedirectRequest{ 72 Path: "/full-path-replacement", 73 }, 74 Namespace: ns, 75 }, { 76 Request: http.Request{ 77 Path: "/path-and-host", 78 UnfollowRedirect: true, 79 }, 80 Response: http.Response{ 81 StatusCode: 302, 82 }, 83 RedirectRequest: &roundtripper.RedirectRequest{ 84 Host: "example.org", 85 Path: "/replacement-prefix", 86 }, 87 Namespace: ns, 88 }, { 89 Request: http.Request{ 90 Path: "/path-and-status", 91 UnfollowRedirect: true, 92 }, 93 Response: http.Response{ 94 StatusCode: 301, 95 }, 96 RedirectRequest: &roundtripper.RedirectRequest{ 97 Path: "/replacement-prefix", 98 }, 99 Namespace: ns, 100 }, { 101 Request: http.Request{ 102 Path: "/full-path-and-host", 103 UnfollowRedirect: true, 104 }, 105 Response: http.Response{ 106 StatusCode: 302, 107 }, 108 RedirectRequest: &roundtripper.RedirectRequest{ 109 Host: "example.org", 110 Path: "/replacement-full", 111 }, 112 Namespace: ns, 113 }, { 114 Request: http.Request{ 115 Path: "/full-path-and-status", 116 UnfollowRedirect: true, 117 }, 118 Response: http.Response{ 119 StatusCode: 301, 120 }, 121 RedirectRequest: &roundtripper.RedirectRequest{ 122 Path: "/replacement-full", 123 }, 124 Namespace: ns, 125 }, 126 } 127 for i := range testCases { 128 // Declare tc here to avoid loop variable 129 // reuse issues across parallel tests. 130 tc := testCases[i] 131 t.Run(tc.GetTestCaseName(i), func(t *testing.T) { 132 t.Parallel() 133 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc) 134 }) 135 } 136 }, 137 }