Skip to content

Commit

Permalink
[Test Runner] Adds suport for split_key, from user_profile tests
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Oct 31, 2022
1 parent 232051b commit 8ec8f8e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions elasticsearch-api/api-spec-testing/rspec_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,24 @@ def compare_pairs(expected_pairs, response, test)

def compare_hash(expected_pairs, actual_hash, test)
expected_pairs.each do |expected_key, expected_value|
# Find the value to compare in the response
split_key = TestFile::Test.split_and_parse_key(expected_key).collect do |k|
# Sometimes the expected *key* is a cached value from a previous request.
test.get_cached_value(k)
# TODO: Refactor! split_key
if (match = expected_key.match(/(^\$[a-z]+)/))
keys = expected_key.split('.')
keys.delete(match[1])
dynamic_key = test.cached_values[match[1].gsub('$', '')]
value = dynamic_key.dig(*keys)

if expected_pairs.values.first.is_a?(String) && expected_pairs.values.first.match?(/^\$/)
return test.cached_values[expected_pairs.values.first.gsub('$','')] == value
else
return expected_pairs.values.first == value
end

else
split_key = TestFile::Test.split_and_parse_key(expected_key).collect do |k|
# Sometimes the expected *key* is a cached value from a previous request.
test.get_cached_value(k)
end
end
# We now accept 'nested.keys' so let's try the previous implementation and if that doesn't
# work, try with the nested key, otherwise, raise exception.
Expand Down

0 comments on commit 8ec8f8e

Please sign in to comment.