@@ -18,6 +18,7 @@ import (
1818 "github.com/splitio/go-toolkit/v5/logging"
1919 "github.com/splitio/go-toolkit/v5/redis"
2020 "github.com/splitio/go-toolkit/v5/redis/mocks"
21+ "github.com/stretchr/testify/assert"
2122)
2223
2324func createSampleSplit (name string , sets []string ) dtos.SplitDTO {
@@ -1372,3 +1373,49 @@ func TestLargeSegmentNames(t *testing.T) {
13721373 t .Error (segments )
13731374 }
13741375}
1376+
1377+ func TestReplaceAll (t * testing.T ) {
1378+ logger := logging .NewLogger (nil )
1379+ prefix := "commons_update_prefix"
1380+
1381+ redisClient , err := NewRedisClient (& conf.RedisConfig {
1382+ Host : "localhost" ,
1383+ Port : 6379 ,
1384+ Prefix : prefix ,
1385+ Database : 1 ,
1386+ }, logger )
1387+ if err != nil {
1388+ t .Error ("It should be nil" )
1389+ }
1390+ toAdd := []dtos.SplitDTO {createSampleSplit ("split1" , []string {}), createSampleSplit ("split2" , []string {}), createSampleSplit ("split3" , []string {})}
1391+
1392+ splitStorage := NewSplitStorage (redisClient , logging .NewLogger (& logging.LoggerOptions {}), flagsets .NewFlagSetFilter (nil ))
1393+ splitStorage .Update (toAdd , []dtos.SplitDTO {}, 1 )
1394+
1395+ splits := splitStorage .All ()
1396+ assert .Equal (t , 3 , len (splits ), "Unexpected amount of split" )
1397+ till , _ := redisClient .Get ("SPLITIO.splits.till" )
1398+ tillInt , _ := strconv .ParseInt (till , 0 , 64 )
1399+ assert .Equal (t , int64 (1 ), tillInt , "ChangeNumber should be 1" )
1400+
1401+ toReplace := []dtos.SplitDTO {createSampleSplit ("split4" , []string {}), createSampleSplit ("split5" , []string {})}
1402+
1403+ splitStorage .ReplaceAll (toReplace , 1 )
1404+
1405+ splits = splitStorage .All ()
1406+ assert .Equal (t , 2 , len (splits ), "Unexpected size" )
1407+
1408+ till , _ = redisClient .Get ("SPLITIO.splits.till" )
1409+ tillInt , _ = strconv .ParseInt (till , 0 , 64 )
1410+ assert .Equal (t , int64 (1 ), tillInt , "ChangeNumber should be 1" )
1411+
1412+ keys := []string {
1413+ "SPLITIO.split.split1" ,
1414+ "SPLITIO.split.split2" ,
1415+ "SPLITIO.split.split3" ,
1416+ "SPLITIO.split.split4" ,
1417+ "SPLITIO.split.split5" ,
1418+ "SPLITIO.splits.till" ,
1419+ }
1420+ redisClient .Del (keys ... )
1421+ }
0 commit comments