Skip to content

Commit

Permalink
Merge pull request #36 from davejohnston/FFM-1251
Browse files Browse the repository at this point in the history
[FFM-1251]: Rules for flags added directly to segment not working
  • Loading branch information
davejohnston committed Aug 16, 2021
2 parents 41b20b7 + 9346bdb commit 073717e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions evaluation/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func (fc FeatureConfig) GetSegmentIdentifiers() StrSlice {
}
}
}

// Append any segments that come from the variation target map
// in addition to the rules above
for _, targetMap := range fc.VariationToTargetMap {
slice = append(slice, targetMap.TargetSegments...)
}
return slice
}

Expand Down
43 changes: 43 additions & 0 deletions evaluation/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package evaluation

import (
"encoding/json"
"reflect"

"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -598,3 +599,45 @@ func TestClause_Evaluate(t *testing.T) {
})
}
}

func segmentMatchServingRule(segments ...string) ServingRules {
return ServingRules{ServingRule{Clauses: Clauses{Clause{Op: segmentMatchOperator, Value: segments}}}}
}
func variationToTargetMap(segments ...string) []VariationMap {
return []VariationMap{
{
TargetSegments: segments,
},
}
}

// TestFeatureConfig_GetSegmentIdentifiers tests that GetSegmentIdentifiers returns the expected data
// given a mixture of clauses and variation target maps
func TestFeatureConfig_GetSegmentIdentifiers(t *testing.T) {
type fields struct {
Rules ServingRules
VariationToTargetMap []VariationMap
}
tests := []struct {
name string
fields fields
want StrSlice
}{
{"test segment returned, that was added from rules", fields{Rules: segmentMatchServingRule("foo")}, StrSlice{"foo"}},
{"test multiple segments returned, that were added from rules", fields{Rules: segmentMatchServingRule("foo", "bar")}, StrSlice{"foo", "bar"}},
{"test segment returned, that was added from variation targetMap", fields{VariationToTargetMap: variationToTargetMap("foo")}, StrSlice{"foo"}},
{"test multiple segments returned, that were added from variation targetMap", fields{VariationToTargetMap: variationToTargetMap("foo", "bar")}, StrSlice{"foo", "bar"}},
{"test multiple segments returned, from both clauses and targetMap", fields{Rules: segmentMatchServingRule("foo"), VariationToTargetMap: variationToTargetMap("bar")}, StrSlice{"foo", "bar"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fc := FeatureConfig{
Rules: tt.fields.Rules,
VariationToTargetMap: tt.fields.VariationToTargetMap,
}
if got := fc.GetSegmentIdentifiers(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetSegmentIdentifiers() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 073717e

Please sign in to comment.