DataDog / datadog-ci-rb

Ruby library for Datadog test visibility
https://docs.datadoghq.com/continuous_integration/tests/ruby
Other
8 stars 4 forks source link

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

Closed anmarchenko closed 4 months ago

anmarchenko commented 4 months ago

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