@@ -17,25 +17,26 @@ import (
1717 "github.com/splitio/go-client/v6/splitio"
1818 "github.com/splitio/go-client/v6/splitio/conf"
1919 impressionlistener "github.com/splitio/go-client/v6/splitio/impressionListener"
20-
21- commonsCfg "github.com/splitio/go-split-commons/v7/conf"
22- "github.com/splitio/go-split-commons/v7/dtos"
23- "github.com/splitio/go-split-commons/v7/engine/evaluator"
24- "github.com/splitio/go-split-commons/v7/engine/evaluator/impressionlabels"
25- evaluatorMock "github.com/splitio/go-split-commons/v7/engine/evaluator/mocks"
26- "github.com/splitio/go-split-commons/v7/healthcheck/application"
27- "github.com/splitio/go-split-commons/v7/provisional"
28- "github.com/splitio/go-split-commons/v7/provisional/strategy"
29- authMocks "github.com/splitio/go-split-commons/v7/service/mocks"
30- "github.com/splitio/go-split-commons/v7/storage"
31- "github.com/splitio/go-split-commons/v7/storage/inmemory"
32- "github.com/splitio/go-split-commons/v7/storage/inmemory/mutexqueue"
33- "github.com/splitio/go-split-commons/v7/storage/mocks"
34- "github.com/splitio/go-split-commons/v7/storage/redis"
35- "github.com/splitio/go-split-commons/v7/synchronizer"
36- syncMock "github.com/splitio/go-split-commons/v7/synchronizer/mocks"
37- "github.com/splitio/go-split-commons/v7/telemetry"
38- "github.com/splitio/go-split-commons/v7/util"
20+ "github.com/stretchr/testify/assert"
21+
22+ commonsCfg "github.com/splitio/go-split-commons/v8/conf"
23+ "github.com/splitio/go-split-commons/v8/dtos"
24+ "github.com/splitio/go-split-commons/v8/engine/evaluator"
25+ "github.com/splitio/go-split-commons/v8/engine/evaluator/impressionlabels"
26+ evaluatorMock "github.com/splitio/go-split-commons/v8/engine/evaluator/mocks"
27+ "github.com/splitio/go-split-commons/v8/healthcheck/application"
28+ "github.com/splitio/go-split-commons/v8/provisional"
29+ "github.com/splitio/go-split-commons/v8/provisional/strategy"
30+ authMocks "github.com/splitio/go-split-commons/v8/service/mocks"
31+ "github.com/splitio/go-split-commons/v8/storage"
32+ "github.com/splitio/go-split-commons/v8/storage/inmemory"
33+ "github.com/splitio/go-split-commons/v8/storage/inmemory/mutexqueue"
34+ "github.com/splitio/go-split-commons/v8/storage/mocks"
35+ "github.com/splitio/go-split-commons/v8/storage/redis"
36+ "github.com/splitio/go-split-commons/v8/synchronizer"
37+ syncMock "github.com/splitio/go-split-commons/v8/synchronizer/mocks"
38+ "github.com/splitio/go-split-commons/v8/telemetry"
39+ "github.com/splitio/go-split-commons/v8/util"
3940
4041 "github.com/splitio/go-toolkit/v5/datastructures/set"
4142 "github.com/splitio/go-toolkit/v5/logging"
@@ -1005,26 +1006,30 @@ func TestBlockUntilReadyInMemoryOk(t *testing.T) {
10051006 mockedSplit3 := dtos.SplitDTO {Name : "split3" , Killed : true , Status : "INACTIVE" }
10061007
10071008 sdkServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1008- time .Sleep (3 * time .Second )
1009- if r .URL .Path != "/splitChanges" || r .Method != "GET" {
1010- t .Error ("Invalid request. Should be GET to /splitChanges" )
1011- }
1009+ switch r .URL .Path {
1010+ case "/version" :
1011+ w .WriteHeader (http .StatusOK )
1012+ case "/splitChanges" :
1013+ time .Sleep (3 * time .Second )
1014+ splitChanges := dtos.RuleChangesDTO {
1015+ FeatureFlags : dtos.FeatureFlagsDTO {
1016+ Splits : []dtos.SplitDTO {mockedSplit1 , mockedSplit2 , mockedSplit3 },
1017+ Since : 3 ,
1018+ Till : 3 ,
1019+ },
1020+ }
10121021
1013- splitChanges := dtos.SplitChangesDTO {
1014- FeatureFlags : dtos.FeatureFlagsDTO {
1015- Splits : []dtos.SplitDTO {mockedSplit1 , mockedSplit2 , mockedSplit3 },
1016- Since : 3 ,
1017- Till : 3 ,
1018- },
1019- }
1022+ raw , err := json .Marshal (splitChanges )
1023+ if err != nil {
1024+ t .Error ("Error building json" )
1025+ return
1026+ }
10201027
1021- raw , err := json .Marshal (splitChanges )
1022- if err != nil {
1023- t .Error ("Error building json" )
1024- return
1028+ w .Write (raw )
1029+ default :
1030+ t .Error ("Unexpected path" )
10251031 }
10261032
1027- w .Write (raw )
10281033 }))
10291034 defer sdkServer .Close ()
10301035
@@ -1150,7 +1155,7 @@ func TestBlockUntilReadyInMemoryOk(t *testing.T) {
11501155
11511156 err = client .BlockUntilReady (2 )
11521157 if err != nil {
1153- t .Error ("Wrong message error" )
1158+ t .Error ("Wrong message error" , err . Error () )
11541159 }
11551160
11561161 if ! client .factory .IsReady () || ! manager .factory .IsReady () {
@@ -2443,7 +2448,7 @@ func TestTelemetryMemory(t *testing.T) {
24432448
24442449 sdkServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
24452450 time .Sleep (100 * time .Millisecond )
2446- splitChanges := dtos.SplitChangesDTO {
2451+ splitChanges := dtos.RuleChangesDTO {
24472452 FeatureFlags : dtos.FeatureFlagsDTO {
24482453 Splits : []dtos.SplitDTO {
24492454 {Name : "split1" , Killed : true , Status : "ACTIVE" , DefaultTreatment : "on" },
@@ -3111,6 +3116,115 @@ func TestUnsupportedandSemverMatcherRedis(t *testing.T) {
31113116 }
31123117}
31133118
3119+ var splitRuleBased = & dtos.SplitDTO {
3120+ Algo : 2 ,
3121+ ChangeNumber : 1494593336752 ,
3122+ DefaultTreatment : "off" ,
3123+ Killed : false ,
3124+ Name : "rbsplit" ,
3125+ Seed : - 1992295819 ,
3126+ Status : "ACTIVE" ,
3127+ TrafficAllocation : 100 ,
3128+ TrafficAllocationSeed : - 285565213 ,
3129+ TrafficTypeName : "user" ,
3130+ Configurations : map [string ]string {"on" : "{\" color\" : \" blue\" ,\" size\" : 13}" },
3131+ Conditions : []dtos.ConditionDTO {
3132+ {
3133+ ConditionType : "ROLLOUT" ,
3134+ Label : "default rule" ,
3135+ MatcherGroup : dtos.MatcherGroupDTO {
3136+ Combiner : "AND" ,
3137+ Matchers : []dtos.MatcherDTO {
3138+ {
3139+ KeySelector : & dtos.KeySelectorDTO {
3140+ TrafficType : "user" ,
3141+ },
3142+ MatcherType : "IN_RULE_BASED_SEGMENT" ,
3143+ UserDefinedSegment : & dtos.UserDefinedSegmentMatcherDataDTO {
3144+ SegmentName : "rbsegment1" ,
3145+ },
3146+ Negate : false ,
3147+ },
3148+ },
3149+ },
3150+ Partitions : []dtos.PartitionDTO {
3151+ {
3152+ Size : 100 ,
3153+ Treatment : "on" ,
3154+ },
3155+ {
3156+ Size : 0 ,
3157+ Treatment : "off" ,
3158+ },
3159+ },
3160+ },
3161+ },
3162+ }
3163+
3164+ var rbsegment1 = & dtos.RuleBasedSegmentDTO {
3165+ Name : "rbsegment1" ,
3166+ Conditions : []dtos.RuleBasedConditionDTO {
3167+ {
3168+ MatcherGroup : dtos.MatcherGroupDTO {
3169+ Combiner : "AND" ,
3170+ Matchers : []dtos.MatcherDTO {
3171+ {
3172+ KeySelector : & dtos.KeySelectorDTO {
3173+ TrafficType : "user" ,
3174+ Attribute : & attribute ,
3175+ },
3176+ MatcherType : "EQUAL_TO_SEMVER" ,
3177+ String : & semver ,
3178+ Whitelist : nil ,
3179+ Negate : false ,
3180+ },
3181+ },
3182+ },
3183+ },
3184+ },
3185+ TrafficTypeName : "user" ,
3186+ }
3187+
3188+ func TestRuleBasedSegmentRedis (t * testing.T ) {
3189+ redisConfig := & commonsCfg.RedisConfig {
3190+ Host : "localhost" ,
3191+ Port : 6379 ,
3192+ Password : "" ,
3193+ Prefix : "test-prefix-rulebased" ,
3194+ }
3195+
3196+ prefixedClient , _ := redis .NewRedisClient (redisConfig , logging .NewLogger (& logging.LoggerOptions {}))
3197+ // Clean redis
3198+ defer func () {
3199+ keys , _ := prefixedClient .Keys ("test-prefix-rulebased*" )
3200+ for _ , k := range keys {
3201+ prefixedClient .Del (k )
3202+ }
3203+ }()
3204+ raw , _ := json .Marshal (* splitRuleBased )
3205+ prefixedClient .Set ("SPLITIO.split.rbsplit" , raw , 0 )
3206+ rbraw , _ := json .Marshal (* rbsegment1 )
3207+ prefixedClient .Set ("SPLITIO.rbsegment.rbsegment1" , rbraw , 0 )
3208+
3209+ impTest := & ImpressionListenerTest {}
3210+ cfg := conf .Default ()
3211+ cfg .LabelsEnabled = true
3212+ cfg .Advanced .ImpressionListener = impTest
3213+ cfg .ImpressionsMode = commonsCfg .ImpressionsModeOptimized
3214+ cfg .OperationMode = conf .RedisConsumer
3215+ cfg .Redis = * redisConfig
3216+
3217+ factory , _ := NewSplitFactory ("test" , cfg )
3218+ client := factory .Client ()
3219+
3220+ // Calls treatments to generate one valid impression
3221+ attributes := make (map [string ]interface {})
3222+ attributes ["version" ] = "3.4.5"
3223+ evaluation := client .Treatment ("user1" , "rbsplit" , attributes )
3224+ assert .Equal (t , "on" , evaluation , "evaluation for rbsplit should be on" )
3225+ client .Destroy ()
3226+ }
3227+
31143228func TestPrerequisites (t * testing.T ) {
31153229 var isDestroyCalled = false
31163230 var splitsMock , _ = ioutil .ReadFile ("../../testdata/splits_mock_5.json" )
0 commit comments