[SDTEST-202] Ignore Webmock automatically when making HTTP calls #193
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Prevents WebMock from interfering with Datadog backend communication without requiring any custom configuration on users' side. We do this by using
WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP
in place ofNet::HTTP
(if OriginalNetHTTP is present).One can see that WebMock stores the original Net::HTTP in this constant here:
https://github.com/bblimke/webmock/blob/fc6a2ab897a069d861adbc1c88e51b2cf8aa88ac/lib/webmock/http_lib_adapters/net_http.rb#L14
This change required
datadog-ci
to introduce its own Net::HTTP adapter as well.Motivation
WebMock and VCR are popular libraries that are being used to stub HTTP requests when running tests. This interferes with
datadog-ci
communication to the Datadog backend. Users of datadog-ci have to change WebMock configuration manually to make test visibility work: it is error-prone and hard-to-debug process.How to test the change?
Unit tests are provided. Tested using https://github.com/anmarchenko/rubocop by removing custom webmock configuration and running tests in agentless mode: