@@ -34,88 +34,119 @@ describe('HashKeyInfoStrategy', () => {
34
34
35
35
describe ( 'getInfo' , ( ) => {
36
36
const key = getKeyInfoResponse . name ;
37
- it ( 'should return appropriate value' , async ( ) => {
38
- when ( mockStandaloneRedisClient . sendPipeline )
39
- . calledWith ( [
40
- [ BrowserToolKeysCommands . Ttl , key ] ,
41
- [ BrowserToolHashCommands . HLen , key ] ,
42
- ] )
43
- . mockResolvedValueOnce ( [
44
- [ null , - 1 ] ,
45
- [ null , 10 ] ,
46
- ] ) ;
47
-
48
- when ( mockStandaloneRedisClient . sendPipeline )
49
- . calledWith ( [
50
- [ BrowserToolKeysCommands . MemoryUsage , key , 'samples' , '0' ] ,
51
- ] )
52
- . mockResolvedValueOnce ( [
53
- [ null , 50 ] ,
54
- ] ) ;
55
-
56
- const result = await strategy . getInfo (
57
- mockStandaloneRedisClient ,
58
- key ,
59
- RedisDataType . Hash ,
60
- ) ;
61
-
62
- expect ( result ) . toEqual ( getKeyInfoResponse ) ;
63
- } ) ;
64
37
65
- it ( 'should return size with null value when memory usage fails' , async ( ) => {
66
- const replyError : ReplyError = {
67
- name : 'ReplyError' ,
68
- command : BrowserToolKeysCommands . MemoryUsage ,
69
- message : "ERR unknown command 'memory'" ,
70
- } ;
71
- when ( mockStandaloneRedisClient . sendPipeline )
72
- . calledWith ( [
73
- [ BrowserToolKeysCommands . Ttl , key ] ,
74
- [ BrowserToolHashCommands . HLen , key ] ,
75
- ] )
76
- . mockResolvedValueOnce ( [
77
- [ null , - 1 ] ,
78
- [ null , 10 ] ,
79
- ] ) ;
80
-
81
- when ( mockStandaloneRedisClient . sendPipeline )
82
- . calledWith ( [
83
- [ BrowserToolKeysCommands . MemoryUsage , key , 'samples' , '0' ] ,
84
- ] )
85
- . mockResolvedValueOnce ( [
86
- [ replyError , null ] ,
87
- ] ) ;
88
-
89
- const result = await strategy . getInfo (
90
- mockStandaloneRedisClient ,
91
- key ,
92
- RedisDataType . Hash ,
93
- ) ;
94
-
95
- expect ( result ) . toEqual ( { ...getKeyInfoResponse , size : null } ) ;
38
+ describe ( 'when getSize is true' , ( ) => {
39
+ it ( 'should return all info in single pipeline' , async ( ) => {
40
+ when ( mockStandaloneRedisClient . sendPipeline )
41
+ . calledWith ( [
42
+ [ BrowserToolKeysCommands . Ttl , key ] ,
43
+ [ BrowserToolHashCommands . HLen , key ] ,
44
+ [ BrowserToolKeysCommands . MemoryUsage , key , 'samples' , '0' ] ,
45
+ ] )
46
+ . mockResolvedValueOnce ( [
47
+ [ null , - 1 ] ,
48
+ [ null , 10 ] ,
49
+ [ null , 50 ] ,
50
+ ] ) ;
51
+
52
+ const result = await strategy . getInfo (
53
+ mockStandaloneRedisClient ,
54
+ key ,
55
+ RedisDataType . Hash ,
56
+ true ,
57
+ ) ;
58
+
59
+ expect ( result ) . toEqual ( getKeyInfoResponse ) ;
60
+ } ) ;
96
61
} ) ;
97
62
98
- it ( 'should not check size when length >= 50,000' , async ( ) => {
99
- when ( mockStandaloneRedisClient . sendPipeline )
100
- . calledWith ( [
101
- [ BrowserToolKeysCommands . Ttl , key ] ,
102
- [ BrowserToolHashCommands . HLen , key ] ,
103
- ] )
104
- . mockResolvedValueOnce ( [
105
- [ null , - 1 ] ,
106
- [ null , 50000 ] ,
107
- ] ) ;
108
-
109
- const result = await strategy . getInfo (
110
- mockStandaloneRedisClient ,
111
- key ,
112
- RedisDataType . Hash ,
113
- ) ;
114
-
115
- expect ( result ) . toEqual ( {
116
- ...getKeyInfoResponse ,
117
- length : 50000 ,
118
- size : - 1
63
+ describe ( 'when getSize is false' , ( ) => {
64
+ it ( 'should return appropriate value' , async ( ) => {
65
+ when ( mockStandaloneRedisClient . sendPipeline )
66
+ . calledWith ( [
67
+ [ BrowserToolKeysCommands . Ttl , key ] ,
68
+ [ BrowserToolHashCommands . HLen , key ] ,
69
+ ] )
70
+ . mockResolvedValueOnce ( [
71
+ [ null , - 1 ] ,
72
+ [ null , 10 ] ,
73
+ ] ) ;
74
+
75
+ when ( mockStandaloneRedisClient . sendPipeline )
76
+ . calledWith ( [
77
+ [ BrowserToolKeysCommands . MemoryUsage , key , 'samples' , '0' ] ,
78
+ ] )
79
+ . mockResolvedValueOnce ( [
80
+ [ null , 50 ] ,
81
+ ] ) ;
82
+
83
+ const result = await strategy . getInfo (
84
+ mockStandaloneRedisClient ,
85
+ key ,
86
+ RedisDataType . Hash ,
87
+ false ,
88
+ ) ;
89
+
90
+ expect ( result ) . toEqual ( getKeyInfoResponse ) ;
91
+ } ) ;
92
+
93
+ it ( 'should return size with null value when memory usage fails' , async ( ) => {
94
+ const replyError : ReplyError = {
95
+ name : 'ReplyError' ,
96
+ command : BrowserToolKeysCommands . MemoryUsage ,
97
+ message : "ERR unknown command 'memory'" ,
98
+ } ;
99
+ when ( mockStandaloneRedisClient . sendPipeline )
100
+ . calledWith ( [
101
+ [ BrowserToolKeysCommands . Ttl , key ] ,
102
+ [ BrowserToolHashCommands . HLen , key ] ,
103
+ ] )
104
+ . mockResolvedValueOnce ( [
105
+ [ null , - 1 ] ,
106
+ [ null , 10 ] ,
107
+ ] ) ;
108
+
109
+ when ( mockStandaloneRedisClient . sendPipeline )
110
+ . calledWith ( [
111
+ [ BrowserToolKeysCommands . MemoryUsage , key , 'samples' , '0' ] ,
112
+ ] )
113
+ . mockResolvedValueOnce ( [
114
+ [ replyError , null ] ,
115
+ ] ) ;
116
+
117
+ const result = await strategy . getInfo (
118
+ mockStandaloneRedisClient ,
119
+ key ,
120
+ RedisDataType . Hash ,
121
+ false ,
122
+ ) ;
123
+
124
+ expect ( result ) . toEqual ( { ...getKeyInfoResponse , size : null } ) ;
125
+ } ) ;
126
+
127
+ it ( 'should not check size when length >= 50,000' , async ( ) => {
128
+ when ( mockStandaloneRedisClient . sendPipeline )
129
+ . calledWith ( [
130
+ [ BrowserToolKeysCommands . Ttl , key ] ,
131
+ [ BrowserToolHashCommands . HLen , key ] ,
132
+ ] )
133
+ . mockResolvedValueOnce ( [
134
+ [ null , - 1 ] ,
135
+ [ null , 50000 ] ,
136
+ ] ) ;
137
+
138
+ const result = await strategy . getInfo (
139
+ mockStandaloneRedisClient ,
140
+ key ,
141
+ RedisDataType . Hash ,
142
+ false ,
143
+ ) ;
144
+
145
+ expect ( result ) . toEqual ( {
146
+ ...getKeyInfoResponse ,
147
+ length : 50000 ,
148
+ size : - 1
149
+ } ) ;
119
150
} ) ;
120
151
} ) ;
121
152
} ) ;
0 commit comments