Skip to content

Commit e094c46

Browse files
committed
add test automation framework; auto-tested matches.
1 parent b00da1b commit e094c46

12 files changed

+471
-11
lines changed

.vscode/launch.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,26 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Launch Package",
8+
"name": "Python: test automation",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/tests/test.py",
12+
"console": "integratedTerminal",
13+
"justMyCode": true
14+
},
15+
{
16+
"name": "GO: Launch Program",
917
"type": "go",
1018
"request": "launch",
1119
"mode": "auto",
1220
"program": "${workspaceFolder}",
1321
"args": [
14-
"--bigip-url", "https://10.250.15.180",
15-
"--bigip-username", "admin",
16-
"--bigip-password", "P@ssw0rd123"
22+
"--bigip-url",
23+
"https://10.250.15.180",
24+
"--bigip-username",
25+
"admin",
26+
"--bigip-password",
27+
"P@ssw0rd123"
1728
]
1829
}
1930
]

tests/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
service_type: NodePort
2+
hostname: gateway.test.automation
3+
virtual:
4+
ipaddr: 10.250.18.119

tests/templates/gateway.yaml.j2

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
3+
apiVersion: gateway.networking.k8s.io/v1beta1
4+
kind: Gateway
5+
metadata:
6+
name: gateway
7+
labels:
8+
domain: k8s-gateway.nginx.org
9+
spec:
10+
gatewayClassName: bigip
11+
listeners:
12+
- name: http
13+
port: 80
14+
protocol: HTTP
15+
addresses:
16+
- value: {{ virtual.ipaddr }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
---
3+
4+
apiVersion: gateway.networking.k8s.io/v1beta1
5+
kind: HTTPRoute
6+
metadata:
7+
name: test-match-header
8+
spec:
9+
parentRefs:
10+
- name: gateway
11+
sectionName: http
12+
hostnames:
13+
- {{ hostname }}
14+
rules:
15+
- matches:
16+
- headers:
17+
- name: test
18+
value: automation
19+
backendRefs:
20+
- name: test-service
21+
port: 80
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
---
3+
4+
apiVersion: gateway.networking.k8s.io/v1beta1
5+
kind: HTTPRoute
6+
metadata:
7+
name: test-match-method
8+
spec:
9+
parentRefs:
10+
- name: gateway
11+
sectionName: http
12+
hostnames:
13+
- {{ hostname }}
14+
rules:
15+
- matches:
16+
- method: GET
17+
- method: OPTIONS
18+
backendRefs:
19+
- name: test-service
20+
port: 80
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
---
3+
4+
apiVersion: gateway.networking.k8s.io/v1beta1
5+
kind: HTTPRoute
6+
metadata:
7+
name: test-multiple-rules
8+
spec:
9+
parentRefs:
10+
- name: gateway
11+
sectionName: http
12+
hostnames:
13+
- {{ hostname }}
14+
rules:
15+
- matches:
16+
- method: GET
17+
- method: OPTIONS
18+
backendRefs:
19+
- name: test-service
20+
port: 80
21+
- matches:
22+
- queryParams:
23+
- name: test
24+
value: automation
25+
- path:
26+
type: PathPrefix
27+
value: /path-test
28+
backendRefs:
29+
- name: test-service
30+
port: 80
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
---
3+
4+
apiVersion: gateway.networking.k8s.io/v1beta1
5+
kind: HTTPRoute
6+
metadata:
7+
name: test-match-path
8+
spec:
9+
parentRefs:
10+
- name: gateway
11+
sectionName: http
12+
hostnames:
13+
- {{ hostname }}
14+
rules:
15+
- matches:
16+
- path:
17+
type: PathPrefix
18+
value: /path-test
19+
backendRefs:
20+
- name: test-service
21+
port: 80
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
---
3+
4+
apiVersion: gateway.networking.k8s.io/v1beta1
5+
kind: HTTPRoute
6+
metadata:
7+
name: test-query-params
8+
spec:
9+
parentRefs:
10+
- name: gateway
11+
sectionName: http
12+
hostnames:
13+
- {{ hostname }}
14+
rules:
15+
- matches:
16+
- queryParams:
17+
- name: test
18+
value: automation
19+
backendRefs:
20+
- name: test-service
21+
port: 80

tests/templates/service.yaml.j2

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
---
3+
4+
apiVersion: apps/v1
5+
kind: Deployment
6+
metadata:
7+
name: test-service
8+
spec:
9+
replicas: 20
10+
selector:
11+
matchLabels:
12+
app: test-service
13+
template:
14+
metadata:
15+
labels:
16+
app: test-service
17+
spec:
18+
containers:
19+
- name: test-service
20+
image: nginx:latest
21+
ports:
22+
- containerPort: 80
23+
volumeMounts:
24+
- name: config-volume
25+
mountPath: /etc/nginx/nginx.conf
26+
subPath: nginx.conf
27+
- name: config-volume
28+
mountPath: /etc/nginx/njs/dumps.js
29+
subPath: dumps.js
30+
volumes:
31+
- name: config-volume
32+
configMap:
33+
name: nginx-config
34+
35+
---
36+
37+
apiVersion: v1
38+
kind: Service
39+
metadata:
40+
name: test-service
41+
spec:
42+
type: {{ service_type }}
43+
ports:
44+
- port: 80
45+
targetPort: 80
46+
protocol: TCP
47+
name: http
48+
selector:
49+
app: test-service
50+
51+
---
52+
53+
apiVersion: v1
54+
kind: ConfigMap
55+
metadata:
56+
name: nginx-config
57+
data:
58+
nginx.conf: |
59+
user nginx;
60+
worker_processes 1;
61+
62+
load_module modules/ngx_http_js_module.so;
63+
64+
events {
65+
worker_connections 1024;
66+
}
67+
68+
http {
69+
js_import njs/dumps.js;
70+
server {
71+
listen 80;
72+
server_name localhost;
73+
74+
location / {
75+
js_content dumps.hello;
76+
}
77+
}
78+
}
79+
dumps.js: |
80+
function hello(r) {
81+
let d = {
82+
'queries': r.args,
83+
'headers': r.headersIn,
84+
'version': r.httpVersion,
85+
'method': r.method,
86+
'remote-address': r.remoteAddress,
87+
'body': r.requestText,
88+
'uri': r.uri,
89+
// 'server_name': "bigip.test.service"
90+
}
91+
92+
r.return(200, JSON.stringify(d)+"\n");
93+
}
94+
95+
export default {hello};

tests/templates/testcases.yaml.j2

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
- name: header matching test
2+
context:
3+
- gateway
4+
- hrs-matches-header
5+
- service
6+
request:
7+
url: http://{{ virtual.ipaddr }}
8+
headers:
9+
Host: {{ hostname }}
10+
test: automation
11+
method: GET
12+
queries:
13+
response:
14+
status: 200
15+
body:
16+
uri: /
17+
queries: {}
18+
headers:
19+
Content-Type: text/plain
20+
21+
- name: path matching test
22+
context:
23+
- gateway
24+
- hrs-matches-path
25+
- service
26+
request:
27+
url: http://{{ virtual.ipaddr }}/path-test
28+
headers:
29+
Host: {{ hostname }}
30+
method: GET
31+
queries:
32+
response:
33+
status: 200
34+
body:
35+
uri: /path-test
36+
queries: {}
37+
headers:
38+
Content-Type: text/plain
39+
40+
- name: method matching test
41+
context:
42+
- gateway
43+
- hrs-matches-method
44+
- service
45+
request:
46+
url: http://{{ virtual.ipaddr }}
47+
headers:
48+
Host: {{ hostname }}
49+
method: OPTIONS
50+
queries:
51+
response:
52+
status: 200
53+
body:
54+
uri: /
55+
queries: {}
56+
headers:
57+
Content-Type: text/plain
58+
59+
- name: query matching test
60+
context:
61+
- gateway
62+
- hrs-matches-method
63+
- service
64+
request:
65+
url: http://{{ virtual.ipaddr }}
66+
headers:
67+
Host: {{ hostname }}
68+
method: GET
69+
queries:
70+
test: automation
71+
response:
72+
status: 200
73+
body:
74+
uri: /
75+
queries:
76+
test: automation
77+
headers:
78+
Content-Type: text/plain

0 commit comments

Comments
 (0)