@@ -22,6 +22,9 @@ const mockRedisConfigResponse = ['name', '512'];
22
22
const mockRedisClientsResponse_1 : string = '# Clients\r\nconnected_clients:100\r\n' ;
23
23
const mockRedisClientsResponse_2 : string = '# Clients\r\nconnected_clients:101\r\n' ;
24
24
25
+ const mockRedisServerResponse_1 : string = '# Server\r\nredis_version:6.0.0\r\n' ;
26
+ const mockRedisServerResponse_2 : string = '# Server\r\nredis_version:5.1.1\r\n' ;
27
+
25
28
const mockRedisAclListResponse_1 : string [ ] = [
26
29
'user <pass off resetchannels -@all' ,
27
30
'user default on #d74ff0ee8da3b9806b18c877dbf29bbde50b5bd8e4dad7a3a725000feb82e8f1 ~* &* +@all' ,
@@ -31,6 +34,9 @@ const mockRedisAclListResponse_2: string[] = [
31
34
'user test_2 on nopass ~* &* +@all' ,
32
35
] ;
33
36
37
+ const mockFTListResponse_1 = [ ] ;
38
+ const mockFTListResponse_2 = [ 'idx' ] ;
39
+
34
40
const mockZScanResponse_1 = [
35
41
'0' ,
36
42
[ 123456789 , 123456789 , 12345678910 , 12345678910 ] ,
@@ -103,6 +109,18 @@ const mockBigListKey = {
103
109
name : Buffer . from ( 'name' ) , type : 'list' , length : 1001 , memory : 10 , ttl : - 1 ,
104
110
} ;
105
111
112
+ const mockJSONKey = {
113
+ name : Buffer . from ( 'name' ) , type : 'ReJSON-RL' , length : 1 , memory : 10 , ttl : - 1 ,
114
+ } ;
115
+
116
+ const mockRediSearchStringKey_1 = {
117
+ name : Buffer . from ( 'name' ) , type : 'string' , length : 1 , memory : 512 * 1024 + 1 , ttl : - 1 ,
118
+ } ;
119
+
120
+ const mockRediSearchStringKey_2 = {
121
+ name : Buffer . from ( 'name' ) , type : 'string' , length : 1 , memory : 512 * 1024 , ttl : - 1 ,
122
+ } ;
123
+
106
124
const mockSortedSets = new Array ( 101 ) . fill (
107
125
{
108
126
name : Buffer . from ( 'name' ) , type : 'zset' , length : 10 , memory : 10 , ttl : - 1 ,
@@ -525,4 +543,100 @@ describe('RecommendationProvider', () => {
525
543
expect ( RTSRecommendation ) . toEqual ( null ) ;
526
544
} ) ;
527
545
} ) ;
546
+
547
+ describe ( 'determineRediSearchRecommendation' , ( ) => {
548
+ it ( 'should return rediSearch recommendation when there is JSON key' , async ( ) => {
549
+ when ( nodeClient . sendCommand )
550
+ . calledWith ( jasmine . objectContaining ( { name : 'FT._LIST' } ) )
551
+ . mockResolvedValue ( mockFTListResponse_1 ) ;
552
+
553
+ const redisServerRecommendation = await service
554
+ . determineRediSearchRecommendation ( nodeClient , [ mockJSONKey ] ) ;
555
+ expect ( redisServerRecommendation ) . toEqual ( { name : RECOMMENDATION_NAMES . REDIS_SEARCH } ) ;
556
+ } ) ;
557
+
558
+ it ( 'should return rediSearch recommendation when there is huge string key' , async ( ) => {
559
+ when ( nodeClient . sendCommand )
560
+ . calledWith ( jasmine . objectContaining ( { name : 'FT._LIST' } ) )
561
+ . mockResolvedValue ( mockFTListResponse_1 ) ;
562
+
563
+ const redisServerRecommendation = await service
564
+ . determineRediSearchRecommendation ( nodeClient , [ mockRediSearchStringKey_1 ] ) ;
565
+ expect ( redisServerRecommendation ) . toEqual ( { name : RECOMMENDATION_NAMES . REDIS_SEARCH } ) ;
566
+ } ) ;
567
+
568
+ it ( 'should not return rediSearch recommendation when there is small string key' , async ( ) => {
569
+ when ( nodeClient . sendCommand )
570
+ . calledWith ( jasmine . objectContaining ( { name : 'FT._LIST' } ) )
571
+ . mockResolvedValue ( mockFTListResponse_1 ) ;
572
+
573
+ const redisServerRecommendation = await service
574
+ . determineRediSearchRecommendation ( nodeClient , [ mockRediSearchStringKey_2 ] ) ;
575
+ expect ( redisServerRecommendation ) . toEqual ( null ) ;
576
+ } ) ;
577
+
578
+ it ( 'should not return rediSearch recommendation when there are no indexes' , async ( ) => {
579
+ when ( nodeClient . sendCommand )
580
+ . calledWith ( jasmine . objectContaining ( { name : 'FT._LIST' } ) )
581
+ . mockResolvedValue ( mockFTListResponse_2 ) ;
582
+
583
+ const redisServerRecommendation = await service
584
+ . determineRediSearchRecommendation ( nodeClient , [ mockJSONKey ] ) ;
585
+ expect ( redisServerRecommendation ) . toEqual ( null ) ;
586
+ } ) ;
587
+
588
+ it ( 'should ignore errors when ft command execute with error' , async ( ) => {
589
+ when ( nodeClient . sendCommand )
590
+ . calledWith ( jasmine . objectContaining ( { name : 'FT._LIST' } ) )
591
+ . mockRejectedValue ( "some error" ) ;
592
+
593
+ const redisServerRecommendation = await service
594
+ . determineRediSearchRecommendation ( nodeClient , [ mockJSONKey ] ) ;
595
+ expect ( redisServerRecommendation ) . toEqual ( { name : RECOMMENDATION_NAMES . REDIS_SEARCH } ) ;
596
+ } ) ;
597
+
598
+ it ( 'should ignore errors when ft command execute with error' , async ( ) => {
599
+ when ( nodeClient . sendCommand )
600
+ . calledWith ( jasmine . objectContaining ( { name : 'FT._LIST' } ) )
601
+ . mockRejectedValue ( "some error" ) ;
602
+
603
+ const redisServerRecommendation = await service
604
+ . determineRediSearchRecommendation ( nodeClient , [ mockRediSearchStringKey_2 ] ) ;
605
+ expect ( redisServerRecommendation ) . toEqual ( null ) ;
606
+ } ) ;
607
+ } ) ;
608
+
609
+ describe ( 'determineRedisVersionRecommendation' , ( ) => {
610
+ it ( 'should not return redis version recommendation' , async ( ) => {
611
+ when ( nodeClient . sendCommand )
612
+ . calledWith ( jasmine . objectContaining ( { name : 'info' } ) )
613
+ . mockResolvedValue ( mockRedisServerResponse_1 ) ;
614
+
615
+ const redisServerRecommendation = await service
616
+ . determineRedisVersionRecommendation ( nodeClient ) ;
617
+ expect ( redisServerRecommendation ) . toEqual ( null ) ;
618
+ } ) ;
619
+
620
+ it ( 'should return redis version recommendation' , async ( ) => {
621
+ when ( nodeClient . sendCommand )
622
+ . calledWith ( jasmine . objectContaining ( { name : 'info' } ) )
623
+ . mockResolvedValueOnce ( mockRedisServerResponse_2 ) ;
624
+
625
+ const redisServerRecommendation = await service
626
+ . determineRedisVersionRecommendation ( nodeClient ) ;
627
+ expect ( redisServerRecommendation ) . toEqual ( { name : RECOMMENDATION_NAMES . REDIS_VERSION } ) ;
628
+ } ) ;
629
+
630
+ it ( 'should not return redis version recommendation when info command executed with error' ,
631
+ async ( ) => {
632
+ resetAllWhenMocks ( ) ;
633
+ when ( nodeClient . sendCommand )
634
+ . calledWith ( jasmine . objectContaining ( { name : 'info' } ) )
635
+ . mockRejectedValue ( 'some error' ) ;
636
+
637
+ const redisServerRecommendation = await service
638
+ . determineRedisVersionRecommendation ( nodeClient ) ;
639
+ expect ( redisServerRecommendation ) . toEqual ( null ) ;
640
+ } ) ;
641
+ } ) ;
528
642
} ) ;
0 commit comments