diff --git a/test/ingress/conformance/tests/httproute-rewrite-path.go b/test/ingress/conformance/tests/httproute-rewrite-path.go new file mode 100644 index 000000000..7c5cd635f --- /dev/null +++ b/test/ingress/conformance/tests/httproute-rewrite-path.go @@ -0,0 +1,46 @@ +// Copyright (c) 2022 Alibaba Group Holding Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tests + +import ( + "testing" + + "github.com/alibaba/higress/test/ingress/conformance/utils/http" + "github.com/alibaba/higress/test/ingress/conformance/utils/suite" +) + +func init() { + HigressConformanceTests = append(HigressConformanceTests, HTTPRouteRewritePath) +} + +var HTTPRouteRewritePath = suite.ConformanceTest{ + ShortName: "HTTPRouteRewritePath", + Description: "A single Ingress in the higress-conformance-infra namespace uses the rewrite path", + Manifests: []string{"tests/httproute-rewrite-path.yaml"}, + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { + + t.Run("Rewrite HTTPRoute Path", func(t *testing.T) { + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, suite.GatewayAddress, http.ExpectedResponse{ + Request: http.Request{Path: "/svc/foo"}, + ExpectedRequest: &http.ExpectedRequest{ + Request: http.Request{Path: "/foo"}, + }, + Response: http.Response{StatusCode: 200}, + Backend: "infra-backend-v1", + Namespace: "higress-conformance-infra", + }) + }) + }, +} diff --git a/test/ingress/conformance/tests/httproute-rewrite-path.yaml b/test/ingress/conformance/tests/httproute-rewrite-path.yaml new file mode 100644 index 000000000..ded88d937 --- /dev/null +++ b/test/ingress/conformance/tests/httproute-rewrite-path.yaml @@ -0,0 +1,33 @@ +# Copyright (c) 2022 Alibaba Group Holding Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + nginx.ingress.kubernetes.io/rewrite-target: "/$1" + name: httproute-rewrite-path + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - http: + paths: + - pathType: ImplementationSpecific + path: "/svc/(.*)" + backend: + service: + name: infra-backend-v1 + port: + number: 8080 diff --git a/test/ingress/e2e_test.go b/test/ingress/e2e_test.go index aa5f1cf99..cf8610021 100644 --- a/test/ingress/e2e_test.go +++ b/test/ingress/e2e_test.go @@ -18,13 +18,14 @@ import ( "flag" "testing" - "github.com/alibaba/higress/test/ingress/conformance/tests" - "github.com/alibaba/higress/test/ingress/conformance/utils/flags" - "github.com/alibaba/higress/test/ingress/conformance/utils/suite" "github.com/stretchr/testify/require" v1 "k8s.io/api/networking/v1" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/config" + + "github.com/alibaba/higress/test/ingress/conformance/tests" + "github.com/alibaba/higress/test/ingress/conformance/utils/flags" + "github.com/alibaba/higress/test/ingress/conformance/utils/suite" ) func TestHigressConformanceTests(t *testing.T) { @@ -51,6 +52,7 @@ func TestHigressConformanceTests(t *testing.T) { higressTests := []suite.ConformanceTest{ tests.HTTPRouteSimpleSameNamespace, tests.HTTPRouteHostNameSameNamespace, + tests.HTTPRouteRewritePath, } cSuite.Run(t, higressTests)