-
Notifications
You must be signed in to change notification settings - Fork 985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faraday::Adapter::Test stubs now support entire urls (with host) #741
Faraday::Adapter::Test stubs now support entire urls (with host) #741
Conversation
4190ea6
to
cdddb8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job so far.
I just think we lost backwards compatibility this way and we should have tests for both use cases (path only stub and full URL stub).
Please see my comments
lib/faraday/adapter/test.rb
Outdated
request_path, request_query = request_uri.split('?') | ||
request_params = request_query ? | ||
Faraday::Utils.parse_nested_query(request_query) : | ||
{} | ||
# meta is a hash use as carrier | ||
# that will be yielded to consumer block | ||
meta = {} | ||
return path_match?(request_path, meta) && | ||
return host == request_host && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm missing something, this line should break backwards compatibility.
That's because we're now passing the request_host
to be checked, but host
could be nil (in case the stub is created with just a path).
That should cause this condition to fail
@@ -81,7 +94,7 @@ def test_middleware_allow_different_outcomes_for_the_same_request | |||
end | |||
|
|||
def test_yields_env_to_stubs | |||
@stubs.get '/hello' do |env| | |||
@stubs.get 'http://foo.com/hello' do |env| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above regarding the host.
We still want to allow people to stub paths (hence URLs with no host).
We should then keep this tests unchanged and duplicate all of them to test that the stub works WITH and WITHOUT the host specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm actually kind of confused about this. The question is, what does it mean when user doesn't specify any host in the stub? Does it mean the stub should be available for all hosts? I mean, should connection.get('http://domain.com/path')
look for stubs declared like stubs.get('/path')
as well as stubs.get('http://domain.com/path')
.
I think the use case mentioned in the issue (#358 (comment)) is trying to make sure Faraday is hitting the right domain. With my changes is still possible to make stubs with no host, but they'll only match requests with no host as well. Is this wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for not being more clear from the beginning.
The wanted behaviour is the following:
- If a hostname is specified on the stub, then both the hostname AND the path should match.
- If no hostname is specified on the stub (hence only the path), then any hostname should match.
Point 1 will "fix" #358, while point 2 will maintain backward compatibility, as the current behaviour is "stub this path on any host" and we should keep that working as well 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for clarifying! I'll take care of it 😃
@@ -2,7 +2,7 @@ | |||
|
|||
class AuthenticationMiddlewareTest < Faraday::TestCase | |||
def conn | |||
Faraday::Connection.new('http://example.net/') do |builder| | |||
Faraday::Connection.new do |builder| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you have to remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying a domain in the connection forces the stubs to only be available for that domain. Therefore, making connection.get('/path')
(without the host) won't match. I removed this to make the connection domainless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my new comment above on the expected behaviour.
I hope this is clear now, this test should definitely work with the domain in place (it will test point 2 of my comment).
Rather than changing existing tests, your approach should be to duplicate them in order to test both points (old and new behaviour).
Hey @erik-escobedo, sorry I'm just touching base to know if there's any progress on this. |
Totally. I'm working on it right now |
cdddb8d
to
2aabd19
Compare
2aabd19
to
7588f72
Compare
Amazing job @erik-escobedo 👍 |
Thanks! No, I'm not planning to make additional work on this, until you think it's necessary. I've been reading about this issue and I'm ready to help if you give the green light: |
Of course! I'd like to work on this one: #305 |
Sounds great! There's still some discussion around what the current "options" method should be called so please join the discussion and provide a suggestion before working on the PR! |
Addresses issue #358