Skip to content

Commit

Permalink
[FFM-5510]: Fixing the condition in evaluator to consider empty slice…
Browse files Browse the repository at this point in the history
… + expose Evaluate function (harness#104)

[FFM-5510]: Fixing the condition in evaluator to consider empty slice + Exposing Evaluate function
# What: 
Small fix to consider empty slice in the condition for clause evaluation
# Why:
Previously segment.rules would either be nil pointer or pointer to slice with at least one element.
Due to changes made for FFM-4150 we require extra check. 
# Testing:
Locally
  • Loading branch information
akiraqb authored and davejohnston committed Sep 26, 2023
1 parent 3b0fca1 commit fee7e35
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions evaluation/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ func (e Evaluator) isTargetIncludedOrExcludedInSegment(segmentList []string, tar

// Should Target be included via segment rules
rules := segment.Rules
if rules != nil && e.evaluateClauses(*rules, target) {
// if rules is nil pointer or points to the empty slice
if (rules != nil && len(*rules) > 0) && e.evaluateClauses(*rules, target) {
e.logger.Debugf(
"Target %s included in segment %s via rules", target.Name, segment.Name)
return true
Expand Down Expand Up @@ -311,6 +312,12 @@ func (e Evaluator) checkPreRequisite(fc *rest.FeatureConfig, target *Target) (bo
return true, nil
}

// Evaluate exposes evaluate to the caller.
func (e Evaluator) Evaluate(identifier string, target *Target, kind string) (rest.Variation, error) {

return e.evaluate(identifier, target, kind)
}

func (e Evaluator) evaluate(identifier string, target *Target, kind string) (rest.Variation, error) {

if e.query == nil {
Expand All @@ -326,7 +333,7 @@ func (e Evaluator) evaluate(identifier string, target *Target, kind string) (res
}

if flag.Prerequisites != nil {
prereq, err := e.checkPreRequisite(&flag, target)
prereq, err := e.checkPreRequisite(&flag, target) // equivalent of evaluateWithPreReqq
if err != nil || !prereq {
return findVariation(flag.Variations, flag.OffVariation)
}
Expand Down

0 comments on commit fee7e35

Please sign in to comment.