Skip to content
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

[SDTEST-202] Ignore Webmock automatically when making HTTP calls #193

Merged
merged 11 commits into from
Jun 20, 2024

Conversation

anmarchenko
Copy link
Member

@anmarchenko anmarchenko commented Jun 18, 2024

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 of Net::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:
image

@anmarchenko anmarchenko marked this pull request as ready for review June 19, 2024 13:57
@anmarchenko anmarchenko requested review from a team as code owners June 19, 2024 13:57
@anmarchenko anmarchenko requested a review from tonyredondo June 19, 2024 13:57
@anmarchenko anmarchenko merged commit 842fc1c into main Jun 20, 2024
28 checks passed
@anmarchenko anmarchenko deleted the anmarchenko/auto_avoid_webmock branch June 20, 2024 09:27
@github-actions github-actions bot added this to the 1.1.1 milestone Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants