Skip to content

Commit

Permalink
update based on reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Dec 16, 2024
1 parent d6673fb commit 1580e84
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 101 deletions.
24 changes: 11 additions & 13 deletions tests/framework/crossplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ExpectedNginxField struct {
Location string
// Servers are the server names that the directive should exist in.
Servers []string
// Upstream are the upstream names that the directive should exist in.
// Upstreams are the upstream names that the directive should exist in.
Upstreams []string
// ValueSubstringAllowed allows the expected value to be a substring of the real value.
// This makes it easier for cases when real values are complex file names or contain things we
Expand All @@ -54,13 +54,11 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
continue
}

err := validateServerBlockDirectives(expFieldCfg, *directive)
if err != nil {
if err := validateServerBlockDirectives(expFieldCfg, *directive); err != nil {
return err
}

err = validateUpstreamDirectives(expFieldCfg, directive)
if err != nil {
if err := validateUpstreamDirectives(expFieldCfg, directive); err != nil {
return err
}
}
Expand All @@ -78,29 +76,29 @@ func validateServerBlockDirectives(expFieldCfg ExpectedNginxField, directive Dir
for _, serverName := range expFieldCfg.Servers {
if directive.Directive == "server" && getServerName(directive.Block) == serverName {
for _, serverDirective := range directive.Block {
if expFieldCfg.Location == "" && expFieldCfg.fieldFound(serverDirective) {
return nil
if expFieldCfg.Location == "" && !expFieldCfg.fieldFound(serverDirective) {
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, serverDirective.Directive)
} else if serverDirective.Directive == "location" &&
fieldExistsInLocation(serverDirective, expFieldCfg) {
return nil
!fieldExistsInLocation(serverDirective, expFieldCfg) {
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, serverDirective.Directive)
}
}
}
}
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, directive.Directive)
return nil
}

func validateUpstreamDirectives(expFieldCfg ExpectedNginxField, directive *Directive) error {
for _, upstreamName := range expFieldCfg.Upstreams {
if directive.Directive == "upstream" && directive.Args[0] == upstreamName {
for _, upstreamDirective := range directive.Block {
if expFieldCfg.fieldFound(upstreamDirective) {
return nil
if !expFieldCfg.fieldFound(upstreamDirective) {
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, upstreamDirective.Directive)
}
}
}
}
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, directive.Directive)
return nil
}

func getServerName(serverBlock Directives) string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: gateway.nginx.org/v1alpha1
kind: UpstreamSettingsPolicy
metadata:
name: latte-svc-usp
name: does-not-exist
spec:
zoneSize: 512k
targetRefs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: UpstreamSettingsPolicy
metadata:
name: coffee-svc-usp-1
spec:
zoneSize: 64k
zoneSize: 1g
targetRefs:
- group: core
kind: Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: gateway.nginx.org/v1alpha1
kind: UpstreamSettingsPolicy
metadata:
name: coffee-svc-usp-1
name: z-coffee-svc-usp
spec:
zoneSize: 64k
targetRefs:
Expand All @@ -12,7 +12,7 @@ spec:
apiVersion: gateway.nginx.org/v1alpha1
kind: UpstreamSettingsPolicy
metadata:
name: coffee-svc-usp-2
name: a-coffee-svc-usp
spec:
zoneSize: 128k
targetRefs:
Expand Down
10 changes: 5 additions & 5 deletions tests/suite/manifests/upstream-settings-policy/valid-usps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: UpstreamSettingsPolicy
metadata:
name: multiple-http-svc-usp
spec:
zoneSize: 512k
targetRefs:
- group: core
kind: Service
Expand All @@ -26,8 +25,9 @@ spec:
group: core
kind: Service
name: grpc-backend
zoneSize: 64k
keepAlive:
connections: 10
requests: 3
time: 10s
timeout: 50s
connections: 100
requests: 45
time: 1m
timeout: 5h
Loading

0 comments on commit 1580e84

Please sign in to comment.