Skip to content

Commit

Permalink
simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Oct 17, 2023
1 parent 1591cc9 commit 846b448
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 48 deletions.
42 changes: 1 addition & 41 deletions spec/datadog/ci/configuration/components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,54 +112,14 @@
context "when api key is set" do
let(:api_key) { "api_key" }

it "sets async for test mode and provides transport and shutdown timeout to the write" do
it "sets async for test mode and provides transport and shutdown timeout to the writer" do
expect(settings.tracing.test_mode)
.to have_received(:async=)
.with(true)

expect(settings.tracing.test_mode).to have_received(:writer_options=) do |options|
expect(options[:transport]).to be_kind_of(Datadog::CI::TestVisibility::Transport)
expect(options[:shutdown_timeout]).to eq(60)

api = options[:transport].api
expect(api.api_key).to eq(api_key)

http_client = api.http
expect(http_client.host).to eq("citestcycle-intake.datadoghq.com")
expect(http_client.port).to eq(443)
expect(http_client.ssl).to eq(true)
end
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(settings.tracing.test_mode).to have_received(:writer_options=) do |options|
api = options[:transport].api
expect(api.api_key).to eq(api_key)

http_client = api.http
expect(http_client.host).to eq("localhost")
expect(http_client.port).to eq(5555)
expect(http_client.ssl).to eq(false)
end
end
end

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

it "construct intake url using provided host" do
expect(settings.tracing.test_mode).to have_received(:writer_options=) do |options|
api = options[:transport].api
expect(api.api_key).to eq(api_key)

http_client = api.http
expect(http_client.host).to eq("citestcycle-intake.eu.datadoghq.com")
expect(http_client.port).to eq(443)
expect(http_client.ssl).to eq(true)
end
end
end
end
Expand Down
39 changes: 32 additions & 7 deletions spec/datadog/ci/transport/api/ci_intake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,41 @@

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

before do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: "citestcycle-intake.datad0ghq.com",
port: 443,
ssl: true,
compress: true
).and_return(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)
end

it "produces correct headers and forwards request to HTTP layer" do
expect(http).to receive(:request).with(
path: "path",
Expand Down

0 comments on commit 846b448

Please sign in to comment.