Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add e2e test cases for proxy-rewrite plugin #341

Merged
merged 15 commits into from
Apr 9, 2021
Prev Previous commit
Next Next commit
add more test case and check the body
  • Loading branch information
Firstsawyou committed Apr 8, 2021
commit b15a15adf75f57f767e4b839c3e02752c72927ed
56 changes: 53 additions & 3 deletions test/e2e/plugins/proxy_rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ spec:

s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org").
Expect().
Status(200)
Status(200).
Body().
Contains("origin")
})

ginkgo.It("proxy rewrite request uri and host", func() {
Expand Down Expand Up @@ -108,7 +110,53 @@ spec:

s.NewAPISIXClient().GET("/hello").WithHeader("Host", "test.com").
Expect().
Status(200)
Status(200).
Body().
Contains("origin")
})

ginkgo.It("proxy rewrite request regex_uri and headers", func() {
backendSvc, backendPorts := s.DefaultHTTPBackend()
ar := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2alpha1
kind: ApisixRoute
metadata:
name: httpbin-route
spec:
http:
- name: rule1
match:
hosts:
- test.com
paths:
- /hello/ip
backends:
- serviceName: %s
servicePort: %d
weight: 10
plugins:
- name: proxy-rewrite
enable: true
config:
regex_uri:
- ^/hello/(.*)
- /$1
header:
host: httpbin.org
`, backendSvc, backendPorts[0])

assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))

err := s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of upstreams")
err = s.EnsureNumApisixRoutesCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")

s.NewAPISIXClient().GET("/hello/ip").
Expect().
Status(200).
Body().
Contains("origin")
})

ginkgo.It("disable plugin", func() {
Expand Down Expand Up @@ -146,6 +194,8 @@ spec:

s.NewAPISIXClient().GET("/hello").WithHeader("Host", "httpbin.org").
Expect().
Status(404)
Status(404).
Body().
Contains("404 Route Not Found")
})
})