Skip to content

Commit

Permalink
more specs for Datadog::CI::Span
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Nov 2, 2023
1 parent 6c148e7 commit fb5fdee
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def on_test_step_finished(event)
elsif event.result.ok?
@current_step_span.passed!
elsif event.result.failed?
@current_step_span.failed!(event.result.exception)
@current_step_span.failed!(exception: event.result.exception)
end

@current_step_span.finish
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/minitest/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def after_teardown
when "."
test_span.passed!
when "E", "F"
test_span.failed!(failure)
test_span.failed!(exception: failure)
when "S"
test_span.skipped!(nil, failure.message)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/rspec/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run(example_group_instance, reporter)
when :passed
test_span.passed!
when :failed
test_span.failed!(execution_result.exception)
test_span.failed!(exception: execution_result.exception)
else
test_span.skipped!(execution_result.exception) if execution_result.example_skipped?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def passed!
tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::PASS)
end

def failed!(exception = nil)
def failed!(exception: nil)
tracer_span.status = 1
tracer_span.set_tag(Ext::Test::TAG_STATUS, Ext::Test::Status::FAIL)
tracer_span.set_error(exception) unless exception.nil?
Expand Down
35 changes: 35 additions & 0 deletions spec/datadog/ci/span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,39 @@
end
end
end

describe "#passed!" do
let(:tracer_span) { instance_double(Datadog::Tracing::SpanOperation) }
let(:span) { described_class.new(tracer_span) }

it "sets the status to PASS" do
expect(tracer_span).to receive(:set_tag).with("test.status", "pass")

span.passed!
end
end

describe "#failed!" do
let(:tracer_span) { instance_double(Datadog::Tracing::SpanOperation) }
let(:span) { described_class.new(tracer_span) }

context "when exception is nil" do
it "sets the status to FAIL" do
expect(tracer_span).to receive(:status=).with(1)
expect(tracer_span).to receive(:set_tag).with("test.status", "fail")

span.failed!
end
end

context "when exception is provided" do
it "sets the status to FAIL" do
expect(tracer_span).to receive(:status=).with(1)
expect(tracer_span).to receive(:set_tag).with("test.status", "fail")
expect(tracer_span).to receive(:set_error).with("error")

span.failed!(exception: "error")
end
end
end
end
2 changes: 1 addition & 1 deletion spec/support/tracer_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def produce_test_trace(

case result
when "FAILED"
test.failed!(exception)
test.failed!(exception: exception)
when "SKIPPED"
test.skipped!(exception)
else
Expand Down

0 comments on commit fb5fdee

Please sign in to comment.