Skip to content

Commit 9346bdb

Browse files
author
Dave Johnston
committed
(MAINT) Add unit tests
1 parent 8e52cf0 commit 9346bdb

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

evaluation/feature_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package evaluation
22

33
import (
44
"encoding/json"
5+
"reflect"
56

67
"github.com/stretchr/testify/assert"
78

@@ -598,3 +599,45 @@ func TestClause_Evaluate(t *testing.T) {
598599
})
599600
}
600601
}
602+
603+
func segmentMatchServingRule(segments ...string) ServingRules {
604+
return ServingRules{ServingRule{Clauses: Clauses{Clause{Op: segmentMatchOperator, Value: segments}}}}
605+
}
606+
func variationToTargetMap(segments ...string) []VariationMap {
607+
return []VariationMap{
608+
{
609+
TargetSegments: segments,
610+
},
611+
}
612+
}
613+
614+
// TestFeatureConfig_GetSegmentIdentifiers tests that GetSegmentIdentifiers returns the expected data
615+
// given a mixture of clauses and variation target maps
616+
func TestFeatureConfig_GetSegmentIdentifiers(t *testing.T) {
617+
type fields struct {
618+
Rules ServingRules
619+
VariationToTargetMap []VariationMap
620+
}
621+
tests := []struct {
622+
name string
623+
fields fields
624+
want StrSlice
625+
}{
626+
{"test segment returned, that was added from rules", fields{Rules: segmentMatchServingRule("foo")}, StrSlice{"foo"}},
627+
{"test multiple segments returned, that were added from rules", fields{Rules: segmentMatchServingRule("foo", "bar")}, StrSlice{"foo", "bar"}},
628+
{"test segment returned, that was added from variation targetMap", fields{VariationToTargetMap: variationToTargetMap("foo")}, StrSlice{"foo"}},
629+
{"test multiple segments returned, that were added from variation targetMap", fields{VariationToTargetMap: variationToTargetMap("foo", "bar")}, StrSlice{"foo", "bar"}},
630+
{"test multiple segments returned, from both clauses and targetMap", fields{Rules: segmentMatchServingRule("foo"), VariationToTargetMap: variationToTargetMap("bar")}, StrSlice{"foo", "bar"}},
631+
}
632+
for _, tt := range tests {
633+
t.Run(tt.name, func(t *testing.T) {
634+
fc := FeatureConfig{
635+
Rules: tt.fields.Rules,
636+
VariationToTargetMap: tt.fields.VariationToTargetMap,
637+
}
638+
if got := fc.GetSegmentIdentifiers(); !reflect.DeepEqual(got, tt.want) {
639+
t.Errorf("GetSegmentIdentifiers() = %v, want %v", got, tt.want)
640+
}
641+
})
642+
}
643+
}

0 commit comments

Comments
 (0)