diff --git a/tests/framework/crossplane.go b/tests/framework/crossplane.go index f9e109a47..107d989ef 100644 --- a/tests/framework/crossplane.go +++ b/tests/framework/crossplane.go @@ -41,8 +41,6 @@ type ExpectedNginxField struct { // ValidateNginxFieldExists accepts the nginx config and the configuration for the expected field, // and returns whether or not that field exists where it should. func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) error { - var directiveFoundInServer, directiveFoundInUpstream bool - b, err := json.Marshal(conf) if err != nil { return fmt.Errorf("error marshaling nginx config: %w", err) @@ -61,15 +59,11 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err continue } - directiveFoundInServer = validateServerBlockDirectives(expFieldCfg, *directive) - - directiveFoundInUpstream = validateUpstreamDirectives(expFieldCfg, *directive) - - if len(expFieldCfg.Server) > 0 && directiveFoundInServer { + if len(expFieldCfg.Server) > 0 && fieldExistsInServer(expFieldCfg, *directive) { return nil } - if len(expFieldCfg.Upstream) > 0 && directiveFoundInUpstream { + if len(expFieldCfg.Upstream) > 0 && fieldExistsInUpstream(expFieldCfg, *directive) { return nil } } @@ -78,7 +72,7 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err return fmt.Errorf("directive %s not found in: nginx config %s", expFieldCfg.Directive, string(b)) } -func validateServerBlockDirectives( +func fieldExistsInServer( expFieldCfg ExpectedNginxField, directive Directive, ) bool { @@ -96,7 +90,7 @@ func validateServerBlockDirectives( return fieldFound } -func validateUpstreamDirectives( +func fieldExistsInUpstream( expFieldCfg ExpectedNginxField, directive Directive, ) bool {