Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Nov 22, 2023
1 parent cb563bc commit b8a4c14
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
10 changes: 10 additions & 0 deletions lib/datadog/ci/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ def build_span(tracer_span, tags)

span
end

def set_initial_tags(ci_span, tags)
tags.each do |key, value|
ci_span.set_default_tags
ci_span.set_environment_runtime_tags

ci_span.set_tags(tags)
ci_span.set_tags(environment_tags)
end
end
end
end
end
52 changes: 26 additions & 26 deletions spec/datadog/ci/recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
let(:tags) { {} }
let(:environment_tags) { Datadog::CI::Ext::Environment.tags(ENV) }

let(:ci_span) do
spy("CI object spy")
end

subject(:recorder) { described_class.new }

before do
Expand All @@ -21,15 +25,16 @@
end
end

describe "#trace_test" do
def expect_initialized_test
allow(Datadog::CI::Test).to receive(:new).with(span_op).and_return(ci_test)
expect(ci_test).to receive(:set_default_tags)
expect(ci_test).to receive(:set_environment_runtime_tags)
expect(ci_test).to receive(:set_tags).with(tags)
expect(ci_test).to receive(:set_tags).with(environment_tags)
shared_examples_for "initialize ci span with tags" do
it do
expect(ci_span).to have_received(:set_default_tags)
expect(ci_span).to have_received(:set_environment_runtime_tags)
expect(ci_span).to have_received(:set_tags).with(tags)
expect(ci_span).to have_received(:set_tags).with(environment_tags)
end
end

describe "#trace_test" do
context "when given a block" do
subject(:trace) do
recorder.trace_test(
Expand All @@ -42,7 +47,6 @@ def expect_initialized_test
end

let(:span_op) { Datadog::Tracing::SpanOperation.new(operation_name) }
let(:ci_test) { instance_double(Datadog::CI::Test) }
let(:block) { proc { |s| block_spy.call(s) } }
let(:block_result) { double("result") }
let(:block_spy) { spy("block") }
Expand All @@ -61,7 +65,7 @@ def expect_initialized_test
}
)

expect_initialized_test
allow(Datadog::CI::Test).to receive(:new).with(span_op).and_return(ci_span)

trace_block.call(span_op, trace_op)
end
Expand All @@ -70,7 +74,9 @@ def expect_initialized_test
end

it_behaves_like "internal tracing context"
it { expect(block_spy).to have_received(:call).with(ci_test) }
it_behaves_like "initialize ci span with tags"

it { expect(block_spy).to have_received(:call).with(ci_span) }
it { is_expected.to be(block_result) }
end

Expand All @@ -84,7 +90,6 @@ def expect_initialized_test
)
end
let(:span_op) { Datadog::Tracing::SpanOperation.new(operation_name) }
let(:ci_test) { instance_double(Datadog::CI::Test) }

before do
allow(Datadog::Tracing)
Expand All @@ -99,24 +104,18 @@ def expect_initialized_test
)
.and_return(span_op)

expect_initialized_test
allow(Datadog::CI::Test).to receive(:new).with(span_op).and_return(ci_span)

trace
end

it_behaves_like "internal tracing context"
it { is_expected.to be(ci_test) }
it_behaves_like "initialize ci span with tags"
it { is_expected.to be(ci_span) }
end
end

describe "#trace" do
def expect_initialized_span
allow(Datadog::CI::Span).to receive(:new).with(span_op).and_return(ci_span)
expect(ci_span).to receive(:set_default_tags)
expect(ci_span).to receive(:set_environment_runtime_tags)
expect(ci_span).to receive(:set_tags).with(tags)
end

let(:tags) { {"my_tag" => "my_value"} }
let(:span_type) { "step" }
let(:span_name) { "span name" }
Expand All @@ -134,7 +133,6 @@ def expect_initialized_span
end

let(:span_op) { Datadog::Tracing::SpanOperation.new(span_name) }
let(:ci_span) { instance_double(Datadog::CI::Span) }
let(:block) { proc { |s| block_spy.call(s) } }
let(:block_result) { double("result") }
let(:block_spy) { spy("block") }
Expand All @@ -154,11 +152,12 @@ def expect_initialized_span
trace_block.call(span_op, trace_op)
end

expect_initialized_span
allow(Datadog::CI::Span).to receive(:new).with(span_op).and_return(ci_span)

trace
end

it_behaves_like "initialize ci span with tags"
it { expect(block_spy).to have_received(:call).with(ci_span) }
it { is_expected.to be(block_result) }
end
Expand Down Expand Up @@ -187,11 +186,12 @@ def expect_initialized_span
)
.and_return(span_op)

expect_initialized_span
allow(Datadog::CI::Span).to receive(:new).with(span_op).and_return(ci_span)

trace
end

it_behaves_like "initialize ci span with tags"
it { is_expected.to be(ci_span) }
end
end
Expand Down Expand Up @@ -271,10 +271,10 @@ def expect_initialized_span
}
)
.and_return(span_op)

allow(Datadog::CI::TestSession).to receive(:new).with(span_op).and_return(ci_test_session)
end

it { is_expected.to be(ci_test_session) }
it do
expect(start_test_session.tracer_span).to be(span_op)
end
end
end

0 comments on commit b8a4c14

Please sign in to comment.