Skip to content

Commit

Permalink
Add tests for Error Pages in VS and VSRs
Browse files Browse the repository at this point in the history
  • Loading branch information
dubrovina authored and tellet committed Feb 24, 2020
1 parent 5f13609 commit f176620
Show file tree
Hide file tree
Showing 16 changed files with 672 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/data/virtual-server-error-pages/standard/virtual-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: virtual-server
spec:
host: virtual-server.example.com
upstreams:
- name: backend2
service: backend2-svc
port: 80
- name: backend1
service: backend1-svc
port: 80
routes:
- path: "/backend1"
errorPages:
- codes: [502]
redirect:
code: 307
url: ${scheme}://virtual-server.example.com/error.html
action:
pass: backend1
- path: "/backend2"
errorPages:
- codes: [502]
return:
code: 207
type: application/json
body: |
{\"status\": \"${upstream_status}\",\"message\":\"Forbidden\"}
headers:
- name: x-debug-original-status
value: ${upstream_status}
action:
pass: backend2
35 changes: 35 additions & 0 deletions tests/data/virtual-server-error-pages/virtual-server-invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: virtual-server
spec:
host: virtual-server.example.com
upstreams:
- name: backend2
service: backend2-svc
port: 80
- name: backend1
service: backend1-svc
port: 80
routes:
- path: "/backend1"
errorPages:
- codes: [308]
redirect:
code: 101
url: /relative/path/url.html
action:
pass: backend1
- path: "/backend2"
errorPages:
- codes: [502]
return:
code: 100
type: ±!@£$%^&*()
body: |
{\"status\": \"${status}\",\"message\":\"Forbidden\"}
headers:
- name: x-debug-original-status
value: ${schema}
action:
pass: backend2
52 changes: 52 additions & 0 deletions tests/data/virtual-server-error-pages/virtual-server-matches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: virtual-server
spec:
host: virtual-server.example.com
upstreams:
- name: backend2
service: backend2-svc
port: 80
- name: backend4-stable
service: backend4-stable-svc
port: 80
- name: backend1-future
service: backend1-future-svc
port: 80
- name: backend3-deprecated
service: backend3-deprecated-svc
port: 80
routes:
- path: "/backend1"
matches:
- conditions:
- header: x-version
value: future
action:
pass: backend1-future
- conditions:
- header: x-version
value: deprecated
action:
pass: backend3-deprecated
action:
pass: backend4-stable
errorPages:
- codes: [502, 404]
redirect:
code: 307
url: ${scheme}://virtual-server.example.com/error.html
- path: "/backend2"
errorPages:
- codes: [502]
return:
code: 207
type: application/json
body: |
{\"status\": \"${upstream_status}\",\"message\":\"Forbidden\"}
headers:
- name: x-debug-original-status
value: ${upstream_status}
action:
pass: backend2
43 changes: 43 additions & 0 deletions tests/data/virtual-server-error-pages/virtual-server-splits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: virtual-server
spec:
host: virtual-server.example.com
upstreams:
- name: backend2
service: backend2-svc
port: 80
- name: backend1-v1
service: backend1-svc-v1
port: 80
- name: backend1-v2
service: backend1-svc-v2
port: 80
routes:
- path: "/backend1"
splits:
- weight: 90
action:
pass: backend1-v1
- weight: 10
action:
pass: backend1-v2
errorPages:
- codes: [502]
redirect:
code: 308
url: ${scheme}://virtual-server.example.com/error.html
- path: "/backend2"
errorPages:
- codes: [502]
return:
code: 207
type: application/json
body: |
{\"status\": \"${upstream_status}\",\"message\":\"Forbidden\"}
headers:
- name: x-debug-original-status
value: ${upstream_status}
action:
pass: backend2
29 changes: 29 additions & 0 deletions tests/data/virtual-server-error-pages/virtual-server-updated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: virtual-server
spec:
host: virtual-server.example.com
upstreams:
- name: backend2
service: backend2-svc
port: 80
- name: backend1
service: backend1-svc
port: 80
routes:
- path: "/backend1"
errorPages:
- codes: [502, 404]
redirect:
url: ${scheme}://virtual-server.example.com/error_${http_x_forwarded_proto}.html
action:
pass: backend1
- path: "/backend2"
errorPages:
- codes: [502]
return:
body: |
Hello World!
action:
pass: backend2
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: backends
spec:
host: virtual-server-route.example.com
upstreams:
- name: backend1
service: backend1-svc
port: 80
- name: backend3
service: backend3-svc
port: 80
subroutes:
- path: "/backends/backend1"
errorPages:
- codes: [308]
redirect:
code: 101
url: /relative/path/url.html
action:
pass: backend1
- path: "/backends/backend3"
errorPages:
- codes: [502]
return:
code: 100
type: ±!@£$%^&*()
body: |
{\"status\": \"${status}\",\"message\":\"Forbidden\"}
headers:
- name: x-debug-original-status
value: ${schema}
action:
pass: backend3
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: backends
spec:
host: virtual-server-route.example.com
upstreams:
- name: backend1
service: backend1-svc
port: 80
- name: backend4-stable
service: backend4-stable-svc
port: 80
- name: backend1-future
service: backend1-future-svc
port: 80
- name: backend3-deprecated
service: backend3-deprecated-svc
port: 80
subroutes:
- path: "/backends/backend1"
matches:
- conditions:
- argument: arg1
value: v1
action:
pass: backend1-future
- conditions:
- argument: arg1
value: v2
action:
pass: backend3-deprecated
errorPages:
- codes: [502, 404]
redirect:
code: 307
url: ${scheme}://virtual-server-route.example.com/error.html
action:
pass: backend4-stable
- path: "/backends/backend3"
errorPages:
- codes: [502]
return:
code: 207
type: application/json
body: |
{\"status\": \"${upstream_status}\",\"message\":\"Forbidden\"}
headers:
- name: x-debug-original-status
value: ${upstream_status}
action:
pass: backend3-deprecated
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: backends
spec:
host: virtual-server-route.example.com
upstreams:
- name: backend1-v1
service: backend1-svc-v1
port: 80
- name: backend1-v2
service: backend1-svc-v2
port: 80
- name: backend3
service: backend3-svc
port: 80
subroutes:
- path: "/backends/backend1"
splits:
- weight: 90
action:
pass: backend1-v1
- weight: 10
action:
pass: backend1-v2
errorPages:
- codes: [502]
redirect:
code: 308
url: ${scheme}://virtual-server-route.example.com/error.html
- path: "/backends/backend3"
errorPages:
- codes: [502]
return:
code: 207
type: application/json
body: |
{\"status\": \"${upstream_status}\",\"message\":\"Forbidden\"}
headers:
- name: x-debug-original-status
value: ${upstream_status}
action:
pass: backend3
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: backends
spec:
host: virtual-server-route.example.com
upstreams:
- name: backend1
service: backend1-svc
port: 80
- name: backend3
service: backend3-svc
port: 80
subroutes:
- path: "/backends/backend1"
errorPages:
- codes: [502, 404]
redirect:
url: ${scheme}://virtual-server-route.example.com/error_${http_x_forwarded_proto}.html
action:
pass: backend1
- path: "/backends/backend3"
errorPages:
- codes: [502]
return:
body: |
Hello World!
action:
pass: backend3
Loading

0 comments on commit f176620

Please sign in to comment.