Skip to content

Commit 07d133f

Browse files
committed
add functional tests for snippetsFilter
1 parent 40e5852 commit 07d133f

File tree

10 files changed

+641
-0
lines changed

10 files changed

+641
-0
lines changed

tests/framework/ngf.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func InstallNGF(cfg InstallationConfig, extraArgs ...string) ([]byte, error) {
6767
"--namespace", cfg.Namespace,
6868
"--wait",
6969
"--set", "nginxGateway.productTelemetry.enable=false",
70+
"--set", "nginxGateway.snippetsFilters.enable=true",
7071
}
7172
if cfg.ChartVersion != "" {
7273
args = append(args, "--version", cfg.ChartVersion)
@@ -96,6 +97,7 @@ func UpgradeNGF(cfg InstallationConfig, extraArgs ...string) ([]byte, error) {
9697
"--wait",
9798
"--set", "nginxGateway.productTelemetry.enable=false",
9899
"--set", "nginxGateway.config.logging.level=debug",
100+
"--set", "nginxGateway.snippetsFilter.enable=true",
99101
}
100102
if cfg.ChartVersion != "" {
101103
args = append(args, "--version", cfg.ChartVersion)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: coffee
5+
spec:
6+
parentRefs:
7+
- name: gateway
8+
sectionName: http
9+
hostnames:
10+
- "cafe.example.com"
11+
rules:
12+
- matches:
13+
- path:
14+
type: PathPrefix
15+
value: /coffee
16+
filters:
17+
- type: ExtensionRef
18+
extensionRef:
19+
group: gateway.nginx.org
20+
kind: SnippetsFilter
21+
name: all-contexts
22+
backendRefs:
23+
- name: coffee
24+
port: 80
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: coffee
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: coffee
10+
template:
11+
metadata:
12+
labels:
13+
app: coffee
14+
spec:
15+
containers:
16+
- name: coffee
17+
image: nginxdemos/nginx-hello:plain-text
18+
ports:
19+
- containerPort: 8080
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: coffee
25+
spec:
26+
ports:
27+
- port: 80
28+
targetPort: 8080
29+
protocol: TCP
30+
name: http
31+
selector:
32+
app: coffee
33+
---
34+
apiVersion: apps/v1
35+
kind: Deployment
36+
metadata:
37+
name: tea
38+
spec:
39+
replicas: 1
40+
selector:
41+
matchLabels:
42+
app: tea
43+
template:
44+
metadata:
45+
labels:
46+
app: tea
47+
spec:
48+
containers:
49+
- name: tea
50+
image: nginxdemos/nginx-hello:plain-text
51+
ports:
52+
- containerPort: 8080
53+
---
54+
apiVersion: v1
55+
kind: Service
56+
metadata:
57+
name: tea
58+
spec:
59+
ports:
60+
- port: 80
61+
targetPort: 8080
62+
protocol: TCP
63+
name: http
64+
selector:
65+
app: tea
66+
---
67+
apiVersion: apps/v1
68+
kind: Deployment
69+
metadata:
70+
name: soda
71+
spec:
72+
replicas: 1
73+
selector:
74+
matchLabels:
75+
app: soda
76+
template:
77+
metadata:
78+
labels:
79+
app: soda
80+
spec:
81+
containers:
82+
- name: soda
83+
image: nginxdemos/nginx-hello:plain-text
84+
ports:
85+
- containerPort: 8080
86+
---
87+
apiVersion: v1
88+
kind: Service
89+
metadata:
90+
name: soda
91+
spec:
92+
ports:
93+
- port: 80
94+
targetPort: 8080
95+
protocol: TCP
96+
name: http
97+
selector:
98+
app: soda
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: gateway
5+
spec:
6+
gatewayClassName: nginx
7+
listeners:
8+
- name: http
9+
port: 80
10+
protocol: HTTP
11+
hostname: "*.example.com"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: grpc-backend
5+
spec:
6+
selector:
7+
app: grpc-backend
8+
ports:
9+
- protocol: TCP
10+
port: 8080
11+
targetPort: 50051
12+
---
13+
apiVersion: apps/v1
14+
kind: Deployment
15+
metadata:
16+
name: grpc-backend
17+
labels:
18+
app: grpc-backend
19+
spec:
20+
replicas: 1
21+
selector:
22+
matchLabels:
23+
app: grpc-backend
24+
template:
25+
metadata:
26+
labels:
27+
app: grpc-backend
28+
spec:
29+
containers:
30+
- name: grpc-backend
31+
image: ghcr.io/nginxinc/kic-test-grpc-server:0.2.2
32+
env:
33+
- name: POD_NAME
34+
valueFrom:
35+
fieldRef:
36+
fieldPath: metadata.name
37+
resources:
38+
requests:
39+
cpu: 10m
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: GRPCRoute
3+
metadata:
4+
name: grpc-route
5+
spec:
6+
parentRefs:
7+
- name: gateway
8+
sectionName: http
9+
rules:
10+
- matches:
11+
- method:
12+
service: helloworld.Greeter
13+
method: SayHello
14+
filters:
15+
- type: ExtensionRef
16+
extensionRef:
17+
group: gateway.nginx.org
18+
kind: SnippetsFilter
19+
name: grpc-all-contexts
20+
backendRefs:
21+
- name: grpc-backend
22+
port: 8080
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: gateway.nginx.org/v1alpha1
2+
kind: SnippetsFilter
3+
metadata:
4+
name: invalid-context
5+
spec:
6+
snippets:
7+
- context: http
8+
value: aio on;
9+
- context: http.server
10+
value: wrker_priority 0; # wrong context for the directive, should be main.
11+
- context: http.server.location
12+
value: keepalive_time 10s;
13+
---
14+
apiVersion: gateway.networking.k8s.io/v1
15+
kind: HTTPRoute
16+
metadata:
17+
name: soda
18+
spec:
19+
parentRefs:
20+
- name: gateway
21+
sectionName: http
22+
hostnames:
23+
- "cafe.example.com"
24+
rules:
25+
- matches:
26+
- path:
27+
type: Exact
28+
value: /soda
29+
filters:
30+
- type: ExtensionRef
31+
extensionRef:
32+
group: gateway.nginx.org
33+
kind: SnippetsFilter
34+
name: invalid-context
35+
backendRefs:
36+
- name: soda
37+
port: 80
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: gateway.nginx.org/v1alpha1
2+
kind: SnippetsFilter
3+
metadata:
4+
name: duplicate-directive
5+
spec:
6+
snippets:
7+
- context: main
8+
value: worker_processes auto; # already present in the configuration
9+
- context: http
10+
value: aio on;
11+
- context: http.server
12+
value: auth_delay 10s;
13+
- context: http.server.location
14+
value: keepalive_time 10s;
15+
---
16+
apiVersion: gateway.networking.k8s.io/v1
17+
kind: HTTPRoute
18+
metadata:
19+
name: tea
20+
spec:
21+
parentRefs:
22+
- name: gateway
23+
sectionName: http
24+
hostnames:
25+
- "cafe.example.com"
26+
rules:
27+
- matches:
28+
- path:
29+
type: Exact
30+
value: /tea
31+
filters:
32+
- type: ExtensionRef
33+
extensionRef:
34+
group: gateway.nginx.org
35+
kind: SnippetsFilter
36+
name: duplicate-directive
37+
backendRefs:
38+
- name: tea
39+
port: 80
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: gateway.nginx.org/v1alpha1
2+
kind: SnippetsFilter
3+
metadata:
4+
name: all-contexts
5+
spec:
6+
snippets:
7+
- context: main
8+
value: worker_priority 0;
9+
- context: http
10+
value: aio on;
11+
- context: http.server
12+
value: auth_delay 10s;
13+
- context: http.server.location
14+
value: keepalive_time 10s;
15+
---
16+
apiVersion: gateway.nginx.org/v1alpha1
17+
kind: SnippetsFilter
18+
metadata:
19+
name: grpc-all-contexts
20+
spec:
21+
snippets:
22+
- context: main
23+
value: worker_shutdown_timeout 120s;
24+
- context: http
25+
value: types_hash_bucket_size 64;
26+
- context: http.server
27+
value: server_tokens on;
28+
- context: http.server.location
29+
value: tcp_nodelay on;

0 commit comments

Comments
 (0)