googleapis / gax-ruby

Google API Extensions for Ruby
https://rubygems.org/gems/google-gax
BSD 3-Clause "New" or "Revised" License
20 stars 22 forks source link

PathTemplate#match returning different params that given to PathTemplate#render #126

Closed blowmage closed 5 years ago

blowmage commented 6 years ago

While evaluating the behavior of Google::Gax::PathTemplate, I noticed a behavior that surprised me. Consider the following spec that I wrote to try to understand the existing behavior:

it 'match returns the same params that render uses' do
  template = PathTemplate.new('v1/{name=parent/*}')
  params = { 'name' => 'parent/child' }
  path = 'v1/parent/child'

  expect(template.render(symbolize_keys(params))).to eq(path)

  expect(template.match(path)).to eq(params)
end

It fails with the following:

Failures:

  1) Google::Gax::PathTemplate match returns the same params that render uses
     Failure/Error: expect(template.match(path)).to eq(params)

       expected: {"name"=>"parent/child"}
            got: {"name"=>"child"}

       (compared using ==)

       Diff:
       @@ -1,2 +1,2 @@
       -"name" => "parent/child",
       +"name" => "child",

     # ./spec/google/gax/path_template_spec.rb:51:in `block (2 levels) in <top (required)>'

I find this surprising. Can someone verify that the behavior of Google::Gax::PathTemplate#match here is correct? If so, why isn't the value returned not matching the constraint given in the template?

pongad commented 6 years ago

I don't think I'm the expert here, but I think the behavior here is definitely incorrect. The name should be "parent/child".

blowmage commented 6 years ago

You will also note that I had to call symbolize_keys on the hash argument passed to #render, but the return value from #match was a hash with string keys. I don't understand why they are different. Shouldn't they either both use symbols keys or both use strings keys?

evaogbe commented 5 years ago

@jbolinger Any updates?

jbolinger commented 5 years ago

Path templates are being rewritten as part of https://github.com/googleapis/gapic-generator-ruby and this will be addressed in the next major release of this library.

blowmage commented 5 years ago

I'm going to close this. The plan is to remove template handling in this gem.