gapic-generator/test/gapic/routing_headers/explicit_routing_headers_model_test.rb
##
# A helper to compare parsed routing header annotation to the expected.
# In the `expected`, the parameters are grouped by the name of the routing header.
A helper to compare parsed routing header annotation to the expected.
In the `expected`, the parameters are grouped by the name of the routing header.
A helper to compare parsed routing header annotation to the expected . In the ` expected ` the parameters are grouped by the name of the routing header .
def assert_routing_matches expected, actual
    error_msg_end = "\nExpected: \n#{expected.pretty_inspect}\nActual: \n#{actual.pretty_inspect}"
    refute actual.nil?, "Actual should not be nil!#{error_msg_end}"
    assert_equal expected.count, actual.count,
                 "Expected and Actual should have same amount of header keys#{error_msg_end}"
    expected.each do |header_key, exp_val_arr|
      assert actual.key?(header_key), "Actual should has a header key `#{header_key}`!" + error_msg_end
      act_val_arr = actual[header_key]
      assert_equal(exp_val_arr.count, act_val_arr.count,
                   "Expected['#{header_key}'] and Actual['#{header_key}'] "\
                   "should have same amount of parameters" + error_msg_end)
      exp_val_arr.each_with_index do |exp_val, index|
        act_val = act_val_arr[index]
        all_subfields_match = true
        exp_val.each do |exp_subkey, exp_subval|
          subfield_match = act_val.respond_to?(exp_subkey) && exp_subval == act_val.send(exp_subkey)
          all_subfields_match &&= subfield_match
        end
        next if all_subfields_match
        expected_err = "Value from Expected['#{header_key}'] at index #{index}: \n#{exp_val.pretty_inspect}"
        act_err = "Value from Actual['#{header_key}'] at index #{index}: \n#{act_val.pretty_inspect}"
        assert all_subfields_match,
               "Cannot find a match for a value in Expected['#{header_key}'] at index #{index}:\n" \
               "#{expected_err}\n#{act_err}\n" + error_msg_end
      end
    end
  end
def assert_routing_matches expected , actual error_msg_end = "\nExpected: \n#{expected.pretty_inspect}\nActual: \n#{actual.pretty_inspect}" refute actual . nil? , "Actual should not be nil!#{error_msg_end}" assert_equal expected . count , actual . count , "Expected and Actual should have same amount of header keys#{error_msg_end}" expected . each do | header_key , exp_val_arr | assert actual . key? ( header_key ) , "Actual should has a header key `#{header_key}`!" + error_msg_end act_val_arr = actual [ header_key ] assert_equal ( exp_val_arr . count , act_val_arr . count , "Expected['#{header_key}'] and Actual['#{header_key}'] " "should have same amount of parameters" + error_msg_end ) exp_val_arr . each_with_index do | exp_val , index | act_val = act_val_arr [ index ] all_subfields_match = true exp_val . each do | exp_subkey , exp_subval | subfield_match = act_val . respond_to? ( exp_subkey ) && exp_subval == act_val . send ( exp_subkey ) all_subfields_match &&= subfield_match end next if all_subfields_match expected_err = "Value from Expected['#{header_key}'] at index #{index}: \n#{exp_val.pretty_inspect}" act_err = "Value from Actual['#{header_key}'] at index #{index}: \n#{act_val.pretty_inspect}" assert all_subfields_match , "Cannot find a match for a value in Expected['#{header_key}'] at index #{index}:\n" "#{expected_err}\n#{act_err}\n" + error_msg_end end end end
A helper to compare parsed routing header annotation to the expected.
A helper to compare parsed routing header annotation to the expected .
# Base asserts # Per-header analysis # The parameters are grouped by the headers, so first we loop through the header groups # Within the header group, the per-parameter comparison. # The order should match, so the parameter at position `i` in expected # should match the parameter in the position `i` in actual # Compare the keys specified in expected to the fields in actual
expected
actual