-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5de0602
commit d1e57d2
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package matchers | ||
|
||
const ( | ||
// MatcherTypeAllKeys string value | ||
MatcherTypeAllKeys = "ALL_KEYS" | ||
// MatcherTypeInSegment string value | ||
MatcherTypeInSegment = "IN_SEGMENT" | ||
// MatcherTypeWhitelist string value | ||
MatcherTypeWhitelist = "WHITELIST" | ||
// MatcherTypeEqualTo string value | ||
MatcherTypeEqualTo = "EQUAL_TO" | ||
// MatcherTypeGreaterThanOrEqualTo string value | ||
MatcherTypeGreaterThanOrEqualTo = "GREATER_THAN_OR_EQUAL_TO" | ||
// MatcherTypeLessThanOrEqualTo string value | ||
MatcherTypeLessThanOrEqualTo = "LESS_THAN_OR_EQUAL_TO" | ||
// MatcherTypeBetween string value | ||
MatcherTypeBetween = "BETWEEN" | ||
// MatcherTypeEqualToSet string value | ||
MatcherTypeEqualToSet = "EQUAL_TO_SET" | ||
// MatcherTypePartOfSet string value | ||
MatcherTypePartOfSet = "PART_OF_SET" | ||
// MatcherTypeContainsAllOfSet string value | ||
MatcherTypeContainsAllOfSet = "CONTAINS_ALL_OF_SET" | ||
// MatcherTypeContainsAnyOfSet string value | ||
MatcherTypeContainsAnyOfSet = "CONTAINS_ANY_OF_SET" | ||
// MatcherTypeStartsWith string value | ||
MatcherTypeStartsWith = "STARTS_WITH" | ||
// MatcherTypeEndsWith string value | ||
MatcherTypeEndsWith = "ENDS_WITH" | ||
// MatcherTypeContainsString string value | ||
MatcherTypeContainsString = "CONTAINS_STRING" | ||
// MatcherTypeInSplitTreatment string value | ||
MatcherTypeInSplitTreatment = "IN_SPLIT_TREATMENT" | ||
// MatcherTypeEqualToBoolean string value | ||
MatcherTypeEqualToBoolean = "EQUAL_TO_BOOLEAN" | ||
// MatcherTypeMatchesString string value | ||
MatcherTypeMatchesString = "MATCHES_STRING" | ||
// MatcherEqualToSemver string value | ||
MatcherEqualToSemver = "EQUAL_TO_SEMVER" | ||
// MatcherTypeGreaterThanOrEqualToSemver string value | ||
MatcherTypeGreaterThanOrEqualToSemver = "GREATER_THAN_OR_EQUAL_TO_SEMVER" | ||
// MatcherTypeLessThanOrEqualToSemver string value | ||
MatcherTypeLessThanOrEqualToSemver = "LESS_THAN_OR_EQUAL_TO_SEMVER" | ||
// MatcherTypeBetweenSemver string value | ||
MatcherTypeBetweenSemver = "BETWEEN_SEMVER" | ||
// MatcherTypeInListSemver string value | ||
MatcherTypeInListSemver = "IN_LIST_SEMVER" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package specs | ||
|
||
import ( | ||
"github.com/splitio/go-toolkit/v5/sdk/specs/matchers" | ||
) | ||
|
||
type splitVersionFilter struct { | ||
excluded map[string]*map[string]struct{} | ||
} | ||
|
||
func NewSplitVersionFilter() splitVersionFilter { | ||
matchersToExclude := map[string]*map[string]struct{}{ | ||
"1.0": { | ||
matchers.MatcherEqualToSemver: {}, | ||
matchers.MatcherTypeLessThanOrEqualToSemver: {}, | ||
matchers.MatcherTypeGreaterThanOrEqualToSemver: {}, | ||
matchers.MatcherTypeBetweenSemver: {}, | ||
matchers.MatcherTypeInListSemver: {}, | ||
}, | ||
"1.1": {}, | ||
} | ||
return splitVersionFilter{ | ||
excluded: matchersToExclude, | ||
} | ||
} | ||
|
||
func (s *splitVersionFilter) shouldFilter(matcher string, apiVersion string) bool { | ||
forVersion, ok := s.excluded[apiVersion] | ||
if !ok { | ||
return false | ||
} | ||
if _, ok := (*forVersion)[matcher]; ok { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package specs | ||
|
||
import ( | ||
"github.com/splitio/go-toolkit/v5/sdk/specs/matchers" | ||
"testing" | ||
) | ||
|
||
func Test_splitVersionFilter_shouldFilter(t *testing.T) { | ||
filter := NewSplitVersionFilter() | ||
shouldFilter := filter.shouldFilter(matchers.MatcherTypeBetweenSemver, "1.0") | ||
if !shouldFilter { | ||
t.Error("It should filtered") | ||
} | ||
|
||
shouldFilter = filter.shouldFilter(matchers.MatcherTypeEqualTo, "1.0") | ||
if shouldFilter { | ||
t.Error("It should not filtered") | ||
} | ||
|
||
shouldFilter = filter.shouldFilter(matchers.MatcherTypeBetweenSemver, "1.1") | ||
if shouldFilter { | ||
t.Error("It should not filtered") | ||
} | ||
} |