Add support for PathTypeExact
This commit is contained in:
parent
5559a59391
commit
a95d850384
8 changed files with 221 additions and 51 deletions
|
|
@ -25,6 +25,7 @@ import (
|
|||
"k8s.io/component-base/logs"
|
||||
|
||||
// required
|
||||
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
|
|
@ -34,6 +35,7 @@ import (
|
|||
_ "k8s.io/ingress-nginx/test/e2e/dbg"
|
||||
_ "k8s.io/ingress-nginx/test/e2e/defaultbackend"
|
||||
_ "k8s.io/ingress-nginx/test/e2e/gracefulshutdown"
|
||||
_ "k8s.io/ingress-nginx/test/e2e/ingress"
|
||||
_ "k8s.io/ingress-nginx/test/e2e/leaks"
|
||||
_ "k8s.io/ingress-nginx/test/e2e/loadbalance"
|
||||
_ "k8s.io/ingress-nginx/test/e2e/lua"
|
||||
|
|
|
|||
|
|
@ -61,13 +61,6 @@ func Failf(format string, args ...interface{}) {
|
|||
ginkgo.Fail(nowStamp()+": "+msg, 1)
|
||||
}
|
||||
|
||||
// Skipf logs to the INFO logs and skips the test.
|
||||
func Skipf(format string, args ...interface{}) {
|
||||
msg := fmt.Sprintf(format, args...)
|
||||
log("INFO", msg)
|
||||
ginkgo.Skip(nowStamp() + ": " + msg)
|
||||
}
|
||||
|
||||
// RestclientConfig deserializes the contents of a kubeconfig file into a Config object.
|
||||
func RestclientConfig(config, context string) (*api.Config, error) {
|
||||
Logf(">>> config: %s\n", config)
|
||||
|
|
|
|||
117
test/e2e/ingress/pathtype_exact.go
Normal file
117
test/e2e/ingress/pathtype_exact.go
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
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 ingress
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
networkingv1beta1 "k8s.io/api/networking/v1beta1"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
var _ = framework.IngressNginxDescribe("[Ingress] [PathType] exact", func() {
|
||||
f := framework.NewDefaultFramework("exact")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeployment()
|
||||
})
|
||||
|
||||
ginkgo.It("should choose exact location for /exact", func() {
|
||||
if !f.IsIngressV1Ready {
|
||||
ginkgo.Skip("Test requires Kubernetes v1.18 or higher")
|
||||
}
|
||||
|
||||
host := "exact.path"
|
||||
|
||||
annotations := map[string]string{
|
||||
"nginx.ingress.kubernetes.io/configuration-snippet": `more_set_input_headers "pathType: exact";`,
|
||||
}
|
||||
|
||||
var exactPathType = networkingv1beta1.PathTypeExact
|
||||
ing := framework.NewSingleIngress("exact", "/exact", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||
ing.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].PathType = &exactPathType
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
annotations = map[string]string{
|
||||
"nginx.ingress.kubernetes.io/configuration-snippet": `more_set_input_headers "pathType: prefix";`,
|
||||
}
|
||||
|
||||
ing = framework.NewSingleIngress("exact-sufix", "/exact", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return strings.Contains(server, host) &&
|
||||
strings.Contains(server, "location = /exact") &&
|
||||
strings.Contains(server, "location /exact")
|
||||
})
|
||||
|
||||
body := f.HTTPTestClient().
|
||||
GET("/exact").
|
||||
WithHeader("Host", host).
|
||||
Expect().
|
||||
Status(http.StatusOK).
|
||||
Body().
|
||||
Raw()
|
||||
|
||||
assert.NotContains(ginkgo.GinkgoT(), body, "pathtype=prefix")
|
||||
assert.Contains(ginkgo.GinkgoT(), body, "pathtype=exact")
|
||||
|
||||
body = f.HTTPTestClient().
|
||||
GET("/exact/sufix").
|
||||
WithHeader("Host", host).
|
||||
Expect().
|
||||
Status(http.StatusOK).
|
||||
Body().
|
||||
Raw()
|
||||
|
||||
assert.Contains(ginkgo.GinkgoT(), body, "pathtype=prefix")
|
||||
|
||||
annotations = map[string]string{
|
||||
"nginx.ingress.kubernetes.io/configuration-snippet": `
|
||||
more_set_input_headers "pathType: prefix";
|
||||
more_set_input_headers "duplicated: true";
|
||||
`,
|
||||
}
|
||||
|
||||
ing = framework.NewSingleIngress("duplicated-prefix", "/exact", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return strings.Contains(server, host) &&
|
||||
strings.Contains(server, "location = /exact") &&
|
||||
strings.Contains(server, "location /exact")
|
||||
})
|
||||
|
||||
body = f.HTTPTestClient().
|
||||
GET("/exact/sufix").
|
||||
WithHeader("Host", host).
|
||||
Expect().
|
||||
Status(http.StatusOK).
|
||||
Body().
|
||||
Raw()
|
||||
|
||||
assert.Contains(ginkgo.GinkgoT(), body, "pathtype=prefix")
|
||||
assert.NotContains(ginkgo.GinkgoT(), body, "pathtype=exact")
|
||||
assert.NotContains(ginkgo.GinkgoT(), body, "duplicated=true")
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue