Skip to content

Commit

Permalink
tests(path): proposal: e2e tests for regex patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
msfidelis committed Mar 28, 2024
1 parent 7c8af49 commit fb45639
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 additions & 0 deletions test/e2e/ingress/pathtype_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,149 @@ var _ = framework.IngressNginxDescribe("[Ingress] [PathType] prefix checks", fun
Expect().
Status(http.StatusOK)
})

ginkgo.It("should test prefix path using simple regex pattern for /id/{int}", func() {

Check failure on line 72 in test/e2e/ingress/pathtype_prefix.go

View workflow job for this annotation

GitHub Actions / lint

72-112 lines are duplicate of `test/e2e/ingress/pathtype_prefix.go:144-184` (dupl)
host := "echo.com.br"

Check failure on line 73 in test/e2e/ingress/pathtype_prefix.go

View workflow job for this annotation

GitHub Actions / lint

string `echo.com.br` has 4 occurrences, make it a constant (goconst)

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)

Check failure on line 111 in test/e2e/ingress/pathtype_prefix.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
})

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)

Check failure on line 141 in test/e2e/ingress/pathtype_prefix.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
})

ginkgo.It("should test prefix path using fixed path size regex pattern /id/{int}{3}", func() {

Check failure on line 144 in test/e2e/ingress/pathtype_prefix.go

View workflow job for this annotation

GitHub Actions / lint

144-184 lines are duplicate of `test/e2e/ingress/pathtype_prefix.go:72-112` (dupl)
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)

Check failure on line 183 in test/e2e/ingress/pathtype_prefix.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
})

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)

})

})

0 comments on commit fb45639

Please sign in to comment.