Skip to content

Commit

Permalink
added unsupported improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mmelograno committed May 8, 2024
1 parent 4e5faa2 commit f8fa3cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
21 changes: 14 additions & 7 deletions engine/validator/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ import (
)

// OverrideWithUnsupported overrides the split with an unsupported matcher type
func OverrideWithUnsupported(split *dtos.SplitDTO, idx int, jdx int) {
split.Conditions[idx].ConditionType = grammar.ConditionTypeWhitelist
split.Conditions[idx].MatcherGroup.Matchers[jdx].MatcherType = matchers.MatcherTypeAllKeys
split.Conditions[idx].MatcherGroup.Matchers[jdx].String = nil
split.Conditions[idx].Label = impressionlabels.UnsupportedMatcherType
split.Conditions[idx].Partitions = []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}}
func OverrideWithUnsupported() dtos.ConditionDTO {
return dtos.ConditionDTO{
ConditionType: grammar.ConditionTypeWhitelist,
Label: impressionlabels.UnsupportedMatcherType,
Partitions: []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}},
MatcherGroup: dtos.MatcherGroupDTO{
Combiner: "AND",
Matchers: []dtos.MatcherDTO{{
MatcherType: matchers.MatcherTypeAllKeys,
}},
},
}
}

// ProcessMatchers processes the matchers of a split and validates them
Expand All @@ -25,8 +31,9 @@ func ProcessMatchers(split *dtos.SplitDTO, logger logging.LoggerInterface) {
for jdx := range split.Conditions[idx].MatcherGroup.Matchers {
_, err := matchers.BuildMatcher(&split.Conditions[idx].MatcherGroup.Matchers[jdx], &injection.Context{}, logger)
if err != nil {
OverrideWithUnsupported(split, idx, jdx)
split.Conditions = []dtos.ConditionDTO{OverrideWithUnsupported()}
}
return
}
}
}
13 changes: 13 additions & 0 deletions engine/validator/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ import (
"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v5/engine/grammar"
"github.com/splitio/go-split-commons/v5/engine/grammar/matchers"
"github.com/splitio/go-toolkit/v5/common"
"github.com/splitio/go-toolkit/v5/logging"
)

func TestProcessMatchers(t *testing.T) {
split := &dtos.SplitDTO{
Conditions: []dtos.ConditionDTO{
{
ConditionType: grammar.ConditionTypeRollout,
Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}},
MatcherGroup: dtos.MatcherGroupDTO{
Matchers: []dtos.MatcherDTO{
{MatcherType: matchers.MatcherTypeEndsWith, KeySelector: nil, String: common.StringRef("test")},
},
},
},
{
ConditionType: "NEW_MATCHER",
Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}},
Expand All @@ -24,6 +34,9 @@ func TestProcessMatchers(t *testing.T) {
},
}
ProcessMatchers(split, logging.NewLogger(nil))
if len(split.Conditions) != 1 {
t.Error("Conditions should have been overridden")
}
if split.Conditions[0].ConditionType != grammar.ConditionTypeWhitelist {
t.Error("ConditionType should be WHITELIST")
}
Expand Down

0 comments on commit f8fa3cb

Please sign in to comment.