tests(path): proposal: e2e tests for regex patterns
This commit is contained in:
parent
aa947f5bd4
commit
746e1b1efa
1 changed files with 145 additions and 0 deletions
|
@ -68,4 +68,149 @@ var _ = framework.IngressNginxDescribe("[Ingress] [PathType] prefix checks", fun
|
||||||
Expect().
|
Expect().
|
||||||
Status(http.StatusOK)
|
Status(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ginkgo.It("should test prefix path using simple regex pattern for /id/{int}", func() {
|
||||||
|
host := "echo.com.br"
|
||||||
|
|
||||||
|
annotations := map[string]string{
|
||||||
|
"nginx.ingress.kubernetes.io/use-regex": `true`,
|
||||||
|
}
|
||||||
|
|
||||||
|
ing := framework.NewSingleIngress(host, "/id/[0-9]+", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||||
|
f.EnsureIngress(ing)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/1").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusOK)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/12").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusOK)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/123").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusOK)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/aaa").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/123a").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusOK)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
ginkgo.It("should test prefix path using regex pattern for /id/{int} ignoring non-digits characters at end of string", func() {
|
||||||
|
host := "echo.com.br"
|
||||||
|
|
||||||
|
annotations := map[string]string{
|
||||||
|
"nginx.ingress.kubernetes.io/use-regex": `true`,
|
||||||
|
}
|
||||||
|
|
||||||
|
ing := framework.NewSingleIngress(host, "/id/[0-9]+$", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||||
|
f.EnsureIngress(ing)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/1").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusOK)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/aaa").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/123a").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
ginkgo.It("should test prefix path using fixed path size regex pattern /id/{int}{3}", func() {
|
||||||
|
host := "echo.com.br"
|
||||||
|
|
||||||
|
annotations := map[string]string{
|
||||||
|
"nginx.ingress.kubernetes.io/use-regex": `true`,
|
||||||
|
}
|
||||||
|
|
||||||
|
ing := framework.NewSingleIngress(host, "/id/[0-9]{3}$", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||||
|
f.EnsureIngress(ing)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/1").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/12").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/123").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusOK)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/1234").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/123a").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
ginkgo.It("should correctly route multi-segment path patterns", func() {
|
||||||
|
host := "echo.com.br"
|
||||||
|
|
||||||
|
annotations := map[string]string{
|
||||||
|
"nginx.ingress.kubernetes.io/use-regex": `true`,
|
||||||
|
}
|
||||||
|
|
||||||
|
ing := framework.NewSingleIngress(host, "/id/[0-9]+/post/[a-zA-Z]+$", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||||
|
f.EnsureIngress(ing)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/123/post/abc").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusOK)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/123/post/abc123").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
f.HTTPTestClient().
|
||||||
|
GET("/id/abc/post/abc").
|
||||||
|
WithHeader("Host", host).
|
||||||
|
Expect().
|
||||||
|
Status(http.StatusNotFound)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue