Skip to content

Commit b69c193

Browse files
committed
update based on reviews
1 parent 1b13c21 commit b69c193

File tree

4 files changed

+158
-90
lines changed

4 files changed

+158
-90
lines changed

Diff for: tests/framework/crossplane.go

+24-13
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,15 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
5454
continue
5555
}
5656

57-
for _, serverName := range expFieldCfg.Servers {
58-
if directive.Directive == "server" && getServerName(directive.Block) == serverName {
59-
for _, serverDirective := range directive.Block {
60-
if expFieldCfg.Location == "" && expFieldCfg.fieldFound(serverDirective) {
61-
return nil
62-
} else if serverDirective.Directive == "location" &&
63-
fieldExistsInLocation(serverDirective, expFieldCfg) {
64-
return nil
65-
}
66-
}
67-
}
57+
err := validateServerBlockDirectives(expFieldCfg, *directive)
58+
if err != nil {
59+
return err
6860
}
6961

70-
return validateUpstreamDirectives(expFieldCfg, directive)
62+
err = validateUpstreamDirectives(expFieldCfg, directive)
63+
if err != nil {
64+
return err
65+
}
7166
}
7267
}
7368

@@ -79,6 +74,22 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
7974
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, string(b))
8075
}
8176

77+
func validateServerBlockDirectives(expFieldCfg ExpectedNginxField, directive Directive) error {
78+
for _, serverName := range expFieldCfg.Servers {
79+
if directive.Directive == "server" && getServerName(directive.Block) == serverName {
80+
for _, serverDirective := range directive.Block {
81+
if expFieldCfg.Location == "" && expFieldCfg.fieldFound(serverDirective) {
82+
return nil
83+
} else if serverDirective.Directive == "location" &&
84+
fieldExistsInLocation(serverDirective, expFieldCfg) {
85+
return nil
86+
}
87+
}
88+
}
89+
}
90+
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, directive.Directive)
91+
}
92+
8293
func validateUpstreamDirectives(expFieldCfg ExpectedNginxField, directive *Directive) error {
8394
for _, upstreamName := range expFieldCfg.Upstreams {
8495
if directive.Directive == "upstream" && directive.Args[0] == upstreamName {
@@ -89,7 +100,7 @@ func validateUpstreamDirectives(expFieldCfg ExpectedNginxField, directive *Direc
89100
}
90101
}
91102
}
92-
return nil
103+
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, directive.Directive)
93104
}
94105

95106
func getServerName(serverBlock Directives) string {

Diff for: tests/suite/manifests/upstream-settings-policy/invalid-usps.yaml

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
apiVersion: gateway.networking.k8s.io/v1
22
kind: Gateway
33
metadata:
4-
name: gateway-httproute-allowed
4+
name: gateway-not-valid
55
spec:
66
gatewayClassName: nginx
7+
addresses: "10.0.0.1"
78
listeners:
89
- name: http
910
port: 80
1011
protocol: HTTP
1112
hostname: "soda.example.com"
12-
allowedRoutes:
13-
namespaces:
14-
from: All
15-
kinds:
16-
kind: GRPCRoute
1713
---
1814
apiVersion: apps/v1
1915
kind: Deployment

Diff for: tests/suite/manifests/upstream-settings-policy/valid-usps.yaml

+4-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
apiVersion: gateway.nginx.org/v1alpha1
22
kind: UpstreamSettingsPolicy
33
metadata:
4-
name: coffee-svc-usp
4+
name: multiple-http-svc-usp
55
spec:
66
zoneSize: 512k
77
targetRefs:
88
- group: core
99
kind: Service
1010
name: coffee
11+
- group: core
12+
kind: Service
13+
name: tea
1114
keepAlive:
1215
connections: 10
1316
requests: 3
@@ -16,25 +19,6 @@ spec:
1619
---
1720
apiVersion: gateway.nginx.org/v1alpha1
1821
kind: UpstreamSettingsPolicy
19-
metadata:
20-
name: tea-multiple-svc-usp
21-
spec:
22-
zoneSize: 128k
23-
targetRefs:
24-
- group: core
25-
kind: Service
26-
name: tea
27-
- group: core
28-
kind: Service
29-
name: coffee
30-
keepAlive:
31-
connections: 12
32-
requests: 31
33-
time: 20s
34-
timeout: 40s
35-
---
36-
apiVersion: gateway.nginx.org/v1alpha1
37-
kind: UpstreamSettingsPolicy
3822
metadata:
3923
name: grpc-svc-usp
4024
spec:

0 commit comments

Comments
 (0)