Skip to content

Commit

Permalink
spec for CI::Recorder#trace method
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Nov 2, 2023
1 parent f247786 commit b185e26
Showing 1 changed file with 85 additions and 1 deletion.
86 changes: 85 additions & 1 deletion spec/datadog/ci/recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
end
end

describe "::trace_test" do
describe "#trace_test" do
let(:tags) { {} }
let(:test_name) { "test name" }

Expand Down Expand Up @@ -127,6 +127,90 @@
end
end

describe "#trace" do
let(:tags) { {"my_tag" => "my_value"} }
let(:span_type) { "step" }
let(:span_name) { "span name" }

let(:expected_tags) { tags }

context "when given a block" do
subject(:trace) do
recorder.trace(
span_type,
span_name,
tags: tags,
&block
)
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") }

before do
allow(block_spy).to receive(:call).and_return(block_result)

allow(Datadog::Tracing)
.to receive(:trace) do |trace_span_name, trace_span_options, &trace_block|
expect(trace_span_name).to be(span_name)
expect(trace_span_options).to eq(
{
span_type: span_type,
resource: span_name
}
)
trace_block.call(span_op, trace_op)
end

allow(Datadog::Tracing::Contrib::Analytics).to receive(:set_measured)
allow(Datadog::CI::Span).to receive(:new).with(span_op, expected_tags).and_return(ci_span)

trace
end

it_behaves_like "internal tracing context"
it { expect(block_spy).to have_received(:call).with(ci_span) }
it { is_expected.to be(block_result) }
end

context "when not given a block" do
subject(:trace) do
recorder.trace(
span_type,
span_name,
tags: tags
)
end

let(:span_op) { Datadog::Tracing::SpanOperation.new(span_name) }
let(:ci_span) { instance_double(Datadog::CI::Span) }

before do
allow(Datadog::Tracing)
.to receive(:trace)
.with(
span_name,
{
span_type: span_type,
resource: span_name
}
)
.and_return(span_op)

allow(Datadog::Tracing::Contrib::Analytics).to receive(:set_measured)
allow(Datadog::CI::Span).to receive(:new).with(span_op, expected_tags).and_return(ci_span)

trace
end

it_behaves_like "internal tracing context"
it { is_expected.to be(ci_span) }
end
end

# TODO: move to span
# describe "::set_tags!" do
# subject(:set_tags!) { described_class.set_tags!(trace_op, span_op, tags) }
Expand Down

0 comments on commit b185e26

Please sign in to comment.