gapic-generator/test/gapic/routing_headers/explicit_routing_headers_input_match_test.rb
##
# A helper to run multiple test cases for the input match
# and report which of them fail
# Does not encode the result by default to make expected cases more legible
A helper to run multiple test cases for the input match
and report which of them fail
Does not encode the result by default to make expected cases more legible
A helper to run multiple test cases for the input match and report which of them fail Does not encode the result by default to make expected cases more legible
def assert_regex_matches routing, test_cases, percent_encode: false
    test_cases.each do |test_case|
      request = test_case[:request]
      expected = test_case[:expected]
      err_str = "Test case:\nRequest: \n#{request.pretty_inspect}\nExpected: \n#{expected.pretty_inspect}"
      headers = {}
      routing.explicit_params.each do |key, param_arr|
        param_arr.each do |param|
          field_val = request.send param.field.to_s if request.respond_to? param.field.to_s
          if field_val && !field_val.empty? && Regexp.new(param.field_regex_str).match?(field_val)
            headers[key] = Regexp.new(param.field_full_regex_str).match(field_val)[key.to_s]
          end
        end
      end
      err_str = "#{err_str}\nHeaders formed: \n #{headers.pretty_inspect}"
      err_str = "#{err_str}\nRouting: #{routing.explicit_params.pretty_inspect}"
      if percent_encode
        assert_equal expected, URI.encode_www_form(headers), err_str
      else
        assert_equal expected, headers.map { |key, value| "#{key}=#{value}" }.join("&"), err_str
      end
    end
  end
def assert_regex_matches routing , test_cases , percent_encode : false test_cases . each do | test_case | request = test_case [ :request ] expected = test_case [ :expected ] err_str = "Test case:\nRequest: \n#{request.pretty_inspect}\nExpected: \n#{expected.pretty_inspect}" headers = { } routing . explicit_params . each do | key , param_arr | param_arr . each do | param | field_val = request . send param . field . to_s if request . respond_to? param . field . to_s if field_val && ! field_val . empty? && Regexp . new ( param . field_regex_str ) . match? ( field_val ) headers [ key ] = Regexp . new ( param . field_full_regex_str ) . match ( field_val ) [ key . to_s ] end end end err_str = "#{err_str}\nHeaders formed: \n #{headers.pretty_inspect}" err_str = "#{err_str}\nRouting: #{routing.explicit_params.pretty_inspect}" if percent_encode assert_equal expected , URI . encode_www_form ( headers ) , err_str else assert_equal expected , headers . map { | key , value | "#{key}=#{value}" } . join ( "&" ) , err_str end end end
A helper to run multiple test cases for the input match
and report which of them fail
Does not encode the result by default to make expected cases more legible
A helper to run multiple test cases for the input match and report which of them fail Does not encode the result by default to make expected cases more legible
routing
test_cases
percent_encode