From e79ff7ea77309ea7bd5057a239192056038b7e4b Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Mon, 16 Oct 2023 14:24:59 +0200 Subject: [PATCH] adapt compressing payload test to usage of core adapter --- lib/datadog/ci/transport/http.rb | 2 ++ spec/datadog/ci/transport/http_spec.rb | 38 ++++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/datadog/ci/transport/http.rb b/lib/datadog/ci/transport/http.rb index 370bef5b..39ca0d29 100644 --- a/lib/datadog/ci/transport/http.rb +++ b/lib/datadog/ci/transport/http.rb @@ -65,6 +65,8 @@ def adapter @adapter ||= Datadog::Core::Transport::HTTP::Adapters::Net.new(host, port, timeout: timeout, ssl: ssl) end + # this is needed because Datadog::Tracing::Writer is not fully compatiple with Datadog::Core::Transport + # TODO: remove before 1.0 when CI implements its own worker class ResponseDecorator < ::SimpleDelegator def trace_count 0 diff --git a/spec/datadog/ci/transport/http_spec.rb b/spec/datadog/ci/transport/http_spec.rb index d8c0d2f1..69b6d01b 100644 --- a/spec/datadog/ci/transport/http_spec.rb +++ b/spec/datadog/ci/transport/http_spec.rb @@ -105,6 +105,7 @@ env.verb = "post" env end + before do expect(adapter).to receive(:call).with(env).and_return(http_response) end @@ -116,19 +117,32 @@ end end - # context "when compressing payload" do - # let(:headers) { {"Content-Type" => "application/json"} } - # let(:expected_headers) { {"Content-Type" => "application/json", "Content-Encoding" => "gzip"} } - # let(:options) { {compress: true} } - # let(:post_request) { double(:post_request) } + context "when compressing payload" do + let(:headers) { {"Content-Type" => "application/json"} } + let(:expected_headers) { {"Content-Type" => "application/json", "Content-Encoding" => "gzip"} } + let(:options) { {compress: true} } + let(:post_request) { double(:post_request) } + + let(:env) do + env = Datadog::Core::Transport::HTTP::Env.new( + Datadog::Core::Transport::Request.new + ) + env.body = Datadog::CI::Transport::Gzip.compress(payload) + env.path = path + env.headers = headers + env.verb = "post" + env + end + + before do + expect(adapter).to receive(:call).with(env).and_return(http_response) + end - # before do - # expect(::Net::HTTP::Post).to receive(:new).with(path, expected_headers).and_return(post_request) - # expect(post_request).to receive(:body=).with(Datadog::CI::Transport::Gzip.compress(payload)) - # expect(http_connection).to receive(:request).with(post_request).and_return(http_response) - # end + it "produces a response" do + is_expected.to be_a_kind_of(described_class::ResponseDecorator) - # it { expect(request.http_response).to be(http_response) } - # end + expect(response.code).to eq(200) + end + end end end