Skip to content

Commit

Permalink
move HTTP building to Builder from EvpProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Oct 24, 2023
1 parent 52b3a07 commit eb9a8dd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 50 deletions.
7 changes: 5 additions & 2 deletions lib/datadog/ci/transport/api/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ def self.build_ci_test_cycle_api(settings)
end

def self.build_evp_proxy_api(agent_settings)
EvpProxy.new(
http = Datadog::CI::Transport::HTTP.new(
host: agent_settings.hostname,
port: agent_settings.port,
ssl: agent_settings.ssl,
timeout: agent_settings.timeout_seconds
timeout: agent_settings.timeout_seconds,
compress: false
)

EvpProxy.new(http: http)
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions lib/datadog/ci/transport/api/evp_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ module CI
module Transport
module Api
class EvpProxy < Base
def initialize(host:, port:, ssl:, timeout:)
super(
http: Datadog::CI::Transport::HTTP.new(
host: host,
port: port,
ssl: ssl,
timeout: timeout,
compress: false
)
)
end

def request(path:, payload:, verb: "post")
path = "#{Ext::Transport::EVP_PROXY_PATH_PREFIX}#{path.sub(/^\//, "")}"

Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/transport/api/base.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Datadog
class Base
attr_reader http: Datadog::CI::Transport::HTTP

@http: Datadog::CI::Transport::HTTP

def initialize: (http: Datadog::CI::Transport::HTTP) -> void

def request: (path: String, payload: String, ?verb: ::String) -> untyped
Expand Down
2 changes: 0 additions & 2 deletions sig/datadog/ci/transport/api/ci_test_cycle.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ module Datadog
module Api
class CiTestCycle < Base
attr_reader api_key: String
attr_reader http: Datadog::CI::Transport::HTTP

@api_key: String
@http: Datadog::CI::Transport::HTTP

def initialize: (api_key: String, url: String) -> void

Expand Down
6 changes: 0 additions & 6 deletions sig/datadog/ci/transport/api/evp_proxy.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ module Datadog
module Transport
module Api
class EvpProxy < Base
@http: Datadog::CI::Transport::HTTP

@container_id: String?

attr_reader http: Datadog::CI::Transport::HTTP

def initialize: (host: String, port: Integer, ssl: bool, timeout: Integer) -> void

def request: (path: String, payload: String, ?verb: ::String) -> Datadog::CI::Transport::HTTP::ResponseDecorator

private
Expand Down
17 changes: 12 additions & 5 deletions spec/datadog/ci/transport/api/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
describe ".build_evp_proxy_api" do
subject { described_class.build_evp_proxy_api(agent_settings) }

let(:api) { double(:api) }
let(:http) { double(:http) }

let(:agent_settings) do
Datadog::Core::Configuration::AgentSettingsResolver::AgentSettings.new(
adapter: nil,
Expand All @@ -79,14 +82,18 @@
)
end

it "creates EvpProxy" do
expect(Datadog::CI::Transport::Api::EvpProxy).to receive(:new).with(
it "creates and configures http client and EvpProxy" do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: "localhost",
port: 5555,
ssl: false,
timeout: 42
)
subject
timeout: 42,
compress: false
).and_return(http)

expect(Datadog::CI::Transport::Api::EvpProxy).to receive(:new).with(http: http).and_return(api)

expect(subject).to eq(api)
end
end
end
36 changes: 13 additions & 23 deletions spec/datadog/ci/transport/api/evp_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,24 @@

RSpec.describe Datadog::CI::Transport::Api::EvpProxy do
subject do
described_class.new(
host: host,
port: port,
ssl: ssl,
timeout: timeout
)
described_class.new(http: http)
end

let(:host) { "localhost" }
let(:port) { 5555 }
let(:ssl) { false }
let(:timeout) { 42 }

let(:http) { double(:http) }

describe "#initialize" do
it "creates HTTP transport" do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: host,
port: port,
ssl: ssl,
timeout: timeout,
compress: false
).and_return(http)
# describe "#initialize" do
# it "creates HTTP transport" do
# expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
# host: host,
# port: port,
# ssl: ssl,
# timeout: timeout,
# compress: false
# ).and_return(http)

subject
end
end
# subject
# end
# end

describe "#request" do
before do
Expand Down

0 comments on commit eb9a8dd

Please sign in to comment.