-
Notifications
You must be signed in to change notification settings - Fork 13
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
Support API_URLs that include path #41
Changes from 4 commits
bcf405b
1d6b8b2
997adca
9517629
d33a883
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
module WebValve | ||
class FakeServiceWrapper | ||
# lazily resolve the app constant to leverage rails class reloading | ||
def initialize(app_class_name) | ||
@app_class_name = app_class_name | ||
def initialize(service_config) | ||
@service_config = service_config | ||
end | ||
|
||
def call(env) | ||
env['PATH_INFO'] = env['PATH_INFO'].gsub(/\A#{path_prefix}/, '') | ||
app.call(env) | ||
end | ||
|
||
private | ||
|
||
def app | ||
@app_class_name.constantize | ||
@service_config.service_class_name.constantize | ||
end | ||
|
||
def path_prefix | ||
@path_prefix ||= URI::parse(@service_config.service_url).path | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ def reset | |
allowlisted_urls.clear | ||
fake_service_configs.clear | ||
stubbed_urls.clear | ||
WebMock.reset! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was required to prevent global state from mucking up the test run and making this test flake: I was surprised that we leave existing WebMock stubs around even when we clear out the local registry of stubbed URLs. But maybe this shouldn't go here? I could put it in that one test's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems fine. i think reset is only used internally. |
||
end | ||
|
||
# @api private | ||
|
@@ -132,7 +133,7 @@ def webmock_service(config) | |
WebMock.stub_request( | ||
:any, | ||
url_to_regexp(config.service_url) | ||
).to_rack(FakeServiceWrapper.new(config.service_class_name)) | ||
).to_rack(FakeServiceWrapper.new(config)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor API change but it's an internal class right? |
||
end | ||
|
||
def allowlist_service(config) | ||
|
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.
Not sure if we're parsing URLs all over the place and could consolidate onto the config. Thoughts?
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.
yea, it might be nice to have the config expose a
path_prefix
method instead of doing this here. it won't be used anywhere else, but it would be tidy.