Skip to content

Commit

Permalink
adapt compressing payload test to usage of core adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Oct 16, 2023
1 parent 0bb2377 commit e79ff7e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/datadog/ci/transport/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 26 additions & 12 deletions spec/datadog/ci/transport/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
env.verb = "post"
env
end

before do
expect(adapter).to receive(:call).with(env).and_return(http_response)
end
Expand All @@ -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

0 comments on commit e79ff7e

Please sign in to comment.