Navigation Menu

Skip to content

Commit

Permalink
response-comparer: add :ignored_drilldown_keys option
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 13, 2018
1 parent 5bd74c4 commit 96f130f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/groonga-query-log/response-comparer.rb
Expand Up @@ -20,8 +20,9 @@ def initialize(command, response1, response2, options={})
@command = command
@response1 = response1
@response2 = response2
@options = options
@options = options.dup
@options[:care_order] = true if @options[:care_order].nil?
@options[:ignored_drilldown_keys] ||= []
end

def same?
Expand Down Expand Up @@ -255,7 +256,11 @@ def same_drilldowns?
drilldowns2 = @response2.body[1..-1] || []
return false if drilldowns1.size != drilldowns2.size

drilldown_keys = @command.drilldowns
ignored_drilldown_keys = @options[:ignored_drilldown_keys]
drilldowns1.each_with_index do |drilldown1, drilldown_index|
drilldown_key = drilldown_keys[drilldown_index]
next if ignored_drilldown_keys.include?(drilldown_key)
drilldown2 = drilldowns2[drilldown_index]
return false unless same_record_set?(drilldown1, drilldown2)
end
Expand Down
43 changes: 43 additions & 0 deletions test/test-response-comparer.rb
Expand Up @@ -393,6 +393,49 @@ def test_not_same
not same?(response1, response2)
end
end

class IgnoreDrilldownKeysTest < self
def create_response(drilldown1, drilldown2)
[
[
[10],
[["_id", "UInt32"]],
],
[
[drilldown1.size * 2],
[["_key", "ShortText"], ["_nsubrecs", "Int32"]],
*drilldown1,
],
[
[drilldown2.size * 2],
[["_key", "ShortText"], ["_nsubrecs", "Int32"]],
*drilldown2,
],
]
end

def test_same
@command["drilldown"] = "column1, column2"
response1 = create_response([["A", 10], ["B", 2]],
[["a", 11], ["b", 10]])
response2 = create_response([["A", 10], ["B", 2]],
[["a", 99], ["b", 20]])
assert do
same?(response1, response2, ignored_drilldown_keys: ["column2"])
end
end

def test_not_same
@command["drilldown"] = "column1, column2"
response1 = create_response([["A", 10], ["B", 2]],
[["a", 11], ["b", 10]])
response2 = create_response([["A", 10], ["B", 2]],
[["a", 99], ["b", 20]])
assert do
not same?(response1, response2)
end
end
end
end

class ErrorTest < self
Expand Down

0 comments on commit 96f130f

Please sign in to comment.