Skip to content

Commit 1580e84

Browse files
committed
update based on reviews
1 parent d6673fb commit 1580e84

File tree

6 files changed

+124
-101
lines changed

6 files changed

+124
-101
lines changed

tests/framework/crossplane.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type ExpectedNginxField struct {
3030
Location string
3131
// Servers are the server names that the directive should exist in.
3232
Servers []string
33-
// Upstream are the upstream names that the directive should exist in.
33+
// Upstreams are the upstream names that the directive should exist in.
3434
Upstreams []string
3535
// ValueSubstringAllowed allows the expected value to be a substring of the real value.
3636
// This makes it easier for cases when real values are complex file names or contain things we
@@ -54,13 +54,11 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
5454
continue
5555
}
5656

57-
err := validateServerBlockDirectives(expFieldCfg, *directive)
58-
if err != nil {
57+
if err := validateServerBlockDirectives(expFieldCfg, *directive); err != nil {
5958
return err
6059
}
6160

62-
err = validateUpstreamDirectives(expFieldCfg, directive)
63-
if err != nil {
61+
if err := validateUpstreamDirectives(expFieldCfg, directive); err != nil {
6462
return err
6563
}
6664
}
@@ -78,29 +76,29 @@ func validateServerBlockDirectives(expFieldCfg ExpectedNginxField, directive Dir
7876
for _, serverName := range expFieldCfg.Servers {
7977
if directive.Directive == "server" && getServerName(directive.Block) == serverName {
8078
for _, serverDirective := range directive.Block {
81-
if expFieldCfg.Location == "" && expFieldCfg.fieldFound(serverDirective) {
82-
return nil
79+
if expFieldCfg.Location == "" && !expFieldCfg.fieldFound(serverDirective) {
80+
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, serverDirective.Directive)
8381
} else if serverDirective.Directive == "location" &&
84-
fieldExistsInLocation(serverDirective, expFieldCfg) {
85-
return nil
82+
!fieldExistsInLocation(serverDirective, expFieldCfg) {
83+
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, serverDirective.Directive)
8684
}
8785
}
8886
}
8987
}
90-
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, directive.Directive)
88+
return nil
9189
}
9290

9391
func validateUpstreamDirectives(expFieldCfg ExpectedNginxField, directive *Directive) error {
9492
for _, upstreamName := range expFieldCfg.Upstreams {
9593
if directive.Directive == "upstream" && directive.Args[0] == upstreamName {
9694
for _, upstreamDirective := range directive.Block {
97-
if expFieldCfg.fieldFound(upstreamDirective) {
98-
return nil
95+
if !expFieldCfg.fieldFound(upstreamDirective) {
96+
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, upstreamDirective.Directive)
9997
}
10098
}
10199
}
102100
}
103-
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, directive.Directive)
101+
return nil
104102
}
105103

106104
func getServerName(serverBlock Directives) string {

tests/suite/manifests/upstream-settings-policy/invalid-svc-usps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: gateway.nginx.org/v1alpha1
22
kind: UpstreamSettingsPolicy
33
metadata:
4-
name: latte-svc-usp
4+
name: does-not-exist
55
spec:
66
zoneSize: 512k
77
targetRefs:

tests/suite/manifests/upstream-settings-policy/valid-merge-usps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: UpstreamSettingsPolicy
33
metadata:
44
name: coffee-svc-usp-1
55
spec:
6-
zoneSize: 64k
6+
zoneSize: 1g
77
targetRefs:
88
- group: core
99
kind: Service

tests/suite/manifests/upstream-settings-policy/valid-usps-first-wins.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: gateway.nginx.org/v1alpha1
22
kind: UpstreamSettingsPolicy
33
metadata:
4-
name: coffee-svc-usp-1
4+
name: z-coffee-svc-usp
55
spec:
66
zoneSize: 64k
77
targetRefs:
@@ -12,7 +12,7 @@ spec:
1212
apiVersion: gateway.nginx.org/v1alpha1
1313
kind: UpstreamSettingsPolicy
1414
metadata:
15-
name: coffee-svc-usp-2
15+
name: a-coffee-svc-usp
1616
spec:
1717
zoneSize: 128k
1818
targetRefs:

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ kind: UpstreamSettingsPolicy
33
metadata:
44
name: multiple-http-svc-usp
55
spec:
6-
zoneSize: 512k
76
targetRefs:
87
- group: core
98
kind: Service
@@ -26,8 +25,9 @@ spec:
2625
group: core
2726
kind: Service
2827
name: grpc-backend
28+
zoneSize: 64k
2929
keepAlive:
30-
connections: 10
31-
requests: 3
32-
time: 10s
33-
timeout: 50s
30+
connections: 100
31+
requests: 45
32+
time: 1m
33+
timeout: 5h

0 commit comments

Comments
 (0)