@@ -31,37 +31,36 @@ def test_load
3131 end
3232 end
3333
34- def test_parse_command_details
35- keys = %i[ arity flags first last step ] . freeze
34+ def test_parse_command_reply
3635 [
3736 {
3837 rows : [
3938 [ 'get' , 2 , Set [ 'readonly' , 'fast' ] , 1 , 1 , 1 , Set [ '@read' , '@string' , '@fast' ] , Set [ ] , Set [ ] , Set [ ] ] ,
4039 [ 'set' , -3 , Set [ 'write' , 'denyoom' , 'movablekeys' ] , 1 , 1 , 1 , Set [ '@write' , '@string' , '@slow' ] , Set [ ] , Set [ ] , Set [ ] ]
4140 ] ,
4241 want : {
43- 'get' => { arity : 2 , flags : Set [ 'readonly' , 'fast' ] , first : 1 , last : 1 , step : 1 } ,
44- 'set' => { arity : - 3 , flags : Set [ ' write' , 'denyoom' , 'movablekeys' ] , first : 1 , last : 1 , step : 1 }
42+ 'get' => { first_key_position : 1 , write? : false , readonly? : true } ,
43+ 'set' => { first_key_position : 1 , write? : true , readonly? : false }
4544 }
4645 } ,
4746 {
4847 rows : [
4948 [ 'GET' , 2 , Set [ 'readonly' , 'fast' ] , 1 , 1 , 1 , Set [ '@read' , '@string' , '@fast' ] , Set [ ] , Set [ ] , Set [ ] ]
5049 ] ,
5150 want : {
52- 'get' => { arity : 2 , flags : Set [ 'readonly' , 'fast' ] , first : 1 , last : 1 , step : 1 }
51+ 'get' => { first_key_position : 1 , write? : false , readonly? : true }
5352 }
5453 } ,
5554 { rows : [ [ ] ] , want : { } } ,
5655 { rows : [ ] , want : { } } ,
5756 { rows : nil , want : { } }
5857 ] . each_with_index do |c , idx |
5958 msg = "Case: #{ idx } "
60- got = ::RedisClient ::Cluster ::Command . send ( :parse_command_details , c [ :rows ] )
59+ got = ::RedisClient ::Cluster ::Command . send ( :parse_command_reply , c [ :rows ] )
6160 assert_equal ( c [ :want ] . size , got . size , msg )
6261 assert_equal ( c [ :want ] . keys . sort , got . keys . sort , msg )
63- c [ :want ] . each do |k1 , v |
64- keys . each { | k2 | assert_equal ( v [ k2 ] , got [ k1 ] [ k2 ] , "#{ msg } : #{ k2 } " ) }
62+ c [ :want ] . each do |k , v |
63+ assert_equal ( v , got [ k ] . to_h , "#{ msg } : #{ k } " )
6564 end
6665 end
6766 end
@@ -134,60 +133,6 @@ def test_exists?
134133 end
135134 end
136135
137- def test_pick_details
138- keys = %i[ first_key_position write readonly ] . freeze
139- [
140- {
141- details : {
142- 'get' => { arity : 2 , flags : Set [ 'readonly' , 'fast' ] , first : 1 , last : 1 , step : 1 } ,
143- 'set' => { arity : -3 , flags : Set [ 'write' , 'denyoom' , 'movablekeys' ] , first : 1 , last : 1 , step : 1 }
144- } ,
145- want : {
146- 'get' => { first_key_position : 1 , write : false , readonly : true } ,
147- 'set' => { first_key_position : 1 , write : true , readonly : false }
148- }
149- } ,
150- { details : { } , want : { } } ,
151- { details : nil , want : { } }
152- ] . each_with_index do |c , idx |
153- msg = "Case: #{ idx } "
154- cmd = ::RedisClient ::Cluster ::Command . new ( c [ :details ] )
155- got = cmd . send ( :pick_details , c [ :details ] )
156- assert_equal ( c [ :want ] . size , got . size , msg )
157- assert_equal ( c [ :want ] . keys . sort , got . keys . sort , msg )
158- c [ :want ] . each do |k1 , v |
159- keys . each { |k2 | assert_equal ( v [ k2 ] , got [ k1 ] [ k2 ] , "#{ msg } : #{ k2 } " ) }
160- end
161- end
162- end
163-
164- def test_dig_details
165- cmd = ::RedisClient ::Cluster ::Command . new (
166- {
167- 'get' => { arity : 2 , flags : Set [ 'readonly' , 'fast' ] , first : 1 , last : 1 , step : 1 } ,
168- 'set' => { arity : -3 , flags : Set [ 'write' , 'denyoom' , 'movablekeys' ] , first : 1 , last : 1 , step : 1 }
169- }
170- )
171- [
172- { params : { command : %w[ SET foo 1 ] , key : :first_key_position } , want : 1 } ,
173- { params : { command : %w[ SET foo 1 ] , key : :write } , want : true } ,
174- { params : { command : %w[ set foo 1 ] , key : :write } , want : true } ,
175- { params : { command : %w[ SET foo 1 ] , key : :readonly } , want : false } ,
176- { params : { command : %w[ GET foo ] , key : :first_key_position } , want : 1 } ,
177- { params : { command : %w[ GET foo ] , key : :write } , want : false } ,
178- { params : { command : %w[ GET foo ] , key : :readonly } , want : true } ,
179- { params : { command : %w[ get foo ] , key : :readonly } , want : true } ,
180- { params : { command : %w[ UNKNOWN foo ] , key : :readonly } , want : nil } ,
181- { params : { command : [ [ 'SET' ] , 'foo' , 1 ] , key : :write } , want : true } ,
182- { params : { command : [ ] , key : :readonly } , want : nil } ,
183- { params : { command : nil , key : :readonly } , want : nil }
184- ] . each_with_index do |c , idx |
185- msg = "Case: #{ idx } "
186- got = cmd . send ( :dig_details , c [ :params ] [ :command ] , c [ :params ] [ :key ] )
187- c [ :want ] . nil? ? assert_nil ( got , msg ) : assert_equal ( c [ :want ] , got , msg )
188- end
189- end
190-
191136 def test_determine_first_key_position
192137 cmd = ::RedisClient ::Cluster ::Command . load ( @raw_clients )
193138 [
0 commit comments