Skip to content

Commit

Permalink
move HTTP building to Builder from CiTestCycle
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Oct 24, 2023
1 parent eb9a8dd commit 3772633
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 71 deletions.
12 changes: 11 additions & 1 deletion lib/datadog/ci/transport/api/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ def self.build_ci_test_cycle_api(settings)
url = settings.ci.agentless_url ||
"https://#{Ext::Transport::TEST_VISIBILITY_INTAKE_HOST_PREFIX}.#{dd_site}:443"

CiTestCycle.new(api_key: settings.api_key, url: url)
uri = URI.parse(url)
raise "Invalid agentless mode URL: #{url}" if uri.host.nil?

http = Datadog::CI::Transport::HTTP.new(
host: uri.host,
port: uri.port,
ssl: uri.scheme == "https" || uri.port == 443,
compress: true
)

CiTestCycle.new(api_key: settings.api_key, http: http)
end

def self.build_evp_proxy_api(agent_settings)
Expand Down
14 changes: 2 additions & 12 deletions lib/datadog/ci/transport/api/ci_test_cycle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,10 @@ module Api
class CiTestCycle < Base
attr_reader :api_key

def initialize(api_key:, url:)
def initialize(api_key:, http:)
@api_key = api_key

uri = URI.parse(url)
raise "Invalid agentless mode URL: #{url}" if uri.host.nil?

super(
http: Datadog::CI::Transport::HTTP.new(
host: uri.host,
port: uri.port,
ssl: uri.scheme == "https" || uri.port == 443,
compress: true
)
)
super(http: http)
end

private
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/transport/api/ci_test_cycle.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Datadog

@api_key: String

def initialize: (api_key: String, url: String) -> void
def initialize: (api_key: String, http: Datadog::CI::Transport::HTTP) -> void

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

Expand Down
46 changes: 36 additions & 10 deletions spec/datadog/ci/transport/api/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
describe ".build_ci_test_cycle_api" do
subject { described_class.build_ci_test_cycle_api(settings) }

let(:api) { double(:api) }
let(:http) { double(:http) }
let(:agentless_url) { nil }
let(:dd_site) { nil }
let(:api_key) { "api_key" }
Expand All @@ -34,32 +36,56 @@
.and_return(api_key)
end

it "creates CI Intake" do
it "creates and configures http client and CiTestCycle" do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: "citestcycle-intake.datadoghq.com",
port: 443,
ssl: true,
compress: true
).and_return(http)

expect(Datadog::CI::Transport::Api::CiTestCycle).to receive(:new).with(
api_key: "api_key", url: "https://citestcycle-intake.datadoghq.com:443"
)
subject
api_key: "api_key", http: http
).and_return(api)

expect(subject).to eq(api)
end

context "when agentless_url is provided" do
let(:agentless_url) { "http://localhost:5555" }

it "configures transport to use intake URL from settings" do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: "localhost",
port: 5555,
ssl: false,
compress: true
).and_return(http)

expect(Datadog::CI::Transport::Api::CiTestCycle).to receive(:new).with(
api_key: "api_key", url: "http://localhost:5555"
)
subject
api_key: "api_key", http: http
).and_return(api)

expect(subject).to eq(api)
end
end

context "when dd_site is provided" do
let(:dd_site) { "datadoghq.eu" }

it "construct intake url using provided host" do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: "citestcycle-intake.datadoghq.eu",
port: 443,
ssl: true,
compress: true
).and_return(http)

expect(Datadog::CI::Transport::Api::CiTestCycle).to receive(:new).with(
api_key: "api_key", url: "https://citestcycle-intake.datadoghq.eu:443"
)
subject
api_key: "api_key", http: http
).and_return(api)

expect(subject).to eq(api)
end
end
end
Expand Down
34 changes: 1 addition & 33 deletions spec/datadog/ci/transport/api/ci_test_cycle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,13 @@
subject do
described_class.new(
api_key: api_key,
url: url
http: http
)
end

let(:api_key) { "api_key" }
let(:url) { "https://citestcycle-intake.datad0ghq.com:443" }

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

describe "#initialize" do
context "with https URL" do
it "creates SSL transport" do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: "citestcycle-intake.datad0ghq.com",
port: 443,
ssl: true,
compress: true
).and_return(http)

subject
end
end

context "with http URL" do
let(:url) { "http://localhost:5555" }

it "creates http transport without SSL" do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: "localhost",
port: 5555,
ssl: false,
compress: true
).and_return(http)

subject
end
end
end

describe "#request" do
before do
allow(Datadog::CI::Transport::HTTP).to receive(:new).and_return(http)
Expand Down
14 changes: 0 additions & 14 deletions spec/datadog/ci/transport/api/evp_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@

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)

# subject
# end
# end

describe "#request" do
before do
allow(Datadog::CI::Transport::HTTP).to receive(:new).and_return(http)
Expand Down

0 comments on commit 3772633

Please sign in to comment.