From 922986763a40ba04449fd560747fb8a812e43f6a Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Mon, 30 Oct 2023 17:29:02 +0100 Subject: [PATCH] rename Recorder.trace to Recorder.trace_test --- lib/datadog/ci.rb | 6 +- lib/datadog/ci/recorder.rb | 2 +- spec/datadog/ci/recorder_spec.rb | 221 ++++++++++++++++--------------- spec/support/tracer_helpers.rb | 19 ++- 4 files changed, 124 insertions(+), 124 deletions(-) diff --git a/lib/datadog/ci.rb b/lib/datadog/ci.rb index 0b54dc04..5acf8c3f 100644 --- a/lib/datadog/ci.rb +++ b/lib/datadog/ci.rb @@ -25,11 +25,11 @@ def trace_test(test_name, test_suite, service_name, operation_name, tags = {}) tags[:span_options] = span_options if block_given? - Recorder.trace(operation_name, tags) do |span| + Recorder.trace_test(operation_name, tags) do |span| yield Test.new(span) end else - tracer_span = Recorder.trace(operation_name, tags) + tracer_span = Recorder.trace_test(operation_name, tags) Test.new(tracer_span) end end @@ -43,7 +43,7 @@ def trace(span_type, span_name, span_options = {}) yield Span.new(tracer_span) end else - tracer_span = ::Datadog::Tracing.trace(span_name, **span_options) + tracer_span = Datadog::Tracing.trace(span_name, **span_options) Span.new(tracer_span) end end diff --git a/lib/datadog/ci/recorder.rb b/lib/datadog/ci/recorder.rb index d99c5b28..bfe69dc8 100644 --- a/lib/datadog/ci/recorder.rb +++ b/lib/datadog/ci/recorder.rb @@ -14,7 +14,7 @@ module CI # Common behavior for CI tests module Recorder # Creates a new span for a CI test - def self.trace(span_name, options = {}) + def self.trace_test(span_name, options = {}) span_options = { span_type: Ext::AppTypes::TYPE_TEST }.merge(options[:span_options] || {}) diff --git a/spec/datadog/ci/recorder_spec.rb b/spec/datadog/ci/recorder_spec.rb index cee9efac..6c1505ba 100644 --- a/spec/datadog/ci/recorder_spec.rb +++ b/spec/datadog/ci/recorder_spec.rb @@ -37,7 +37,7 @@ let(:options) { {} } context "when given a block" do - subject(:trace) { described_class.trace(span_name, options, &block) } + subject(:trace) { described_class.trace_test(span_name, options, &block) } let(:span_op) { Datadog::Tracing::SpanOperation.new(span_name) } let(:block) { proc { |s| block_spy.call(s) } } let(:block_result) { double("result") } @@ -64,7 +64,7 @@ end context "when not given a block" do - subject(:trace) { described_class.trace(span_name, options) } + subject(:trace) { described_class.trace_test(span_name, options) } let(:span_op) { Datadog::Tracing::SpanOperation.new(span_name) } before do @@ -246,111 +246,114 @@ end end - describe "::passed!" do - subject(:passed!) { described_class.passed!(span_op) } - let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) } - - before do - allow(span_op).to receive(:set_tag) - passed! - end - - it do - expect(span_op) - .to have_received(:set_tag) - .with( - Datadog::CI::Ext::Test::TAG_STATUS, - Datadog::CI::Ext::Test::Status::PASS - ) - end - end - - describe "::failed!" do - let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) } - - before do - allow(span_op).to receive(:status=) - allow(span_op).to receive(:set_tag) - allow(span_op).to receive(:set_error) - failed! - end - - shared_examples "failed test span operation" do - it do - expect(span_op) - .to have_received(:status=) - .with(1) - end - - it do - expect(span_op) - .to have_received(:set_tag) - .with( - Datadog::CI::Ext::Test::TAG_STATUS, - Datadog::CI::Ext::Test::Status::FAIL - ) - end - end - - context "when no exception is given" do - subject(:failed!) { described_class.failed!(span_op) } - - it_behaves_like "failed test span operation" - it { expect(span_op).to_not have_received(:set_error) } - end - - context "when exception is given" do - subject(:failed!) { described_class.failed!(span_op, exception) } - let(:exception) { instance_double(StandardError) } - - it_behaves_like "failed test span operation" - - it do - expect(span_op) - .to have_received(:set_error) - .with(exception) - end - end - end - - describe "::skipped!" do - let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) } - - before do - allow(span_op).to receive(:set_tag) - allow(span_op).to receive(:set_error) - skipped! - end - - shared_examples "skipped test span operation" do - it do - expect(span_op) - .to have_received(:set_tag) - .with( - Datadog::CI::Ext::Test::TAG_STATUS, - Datadog::CI::Ext::Test::Status::SKIP - ) - end - end - - context "when no exception is given" do - subject(:skipped!) { described_class.skipped!(span_op) } - - it_behaves_like "skipped test span operation" - it { expect(span_op).to_not have_received(:set_error) } - end - - context "when exception is given" do - subject(:skipped!) { described_class.skipped!(span_op, exception) } - let(:exception) { instance_double(StandardError) } - - it_behaves_like "skipped test span operation" - - it do - expect(span_op) - .to have_received(:set_error) - .with(exception) - end - end - end + # TODO: move to Span + # describe "::passed!" do + # subject(:passed!) { described_class.passed!(span_op) } + # let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) } + + # before do + # allow(span_op).to receive(:set_tag) + # passed! + # end + + # it do + # expect(span_op) + # .to have_received(:set_tag) + # .with( + # Datadog::CI::Ext::Test::TAG_STATUS, + # Datadog::CI::Ext::Test::Status::PASS + # ) + # end + # end + + # TODO: move to Span + # describe "::failed!" do + # let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) } + + # before do + # allow(span_op).to receive(:status=) + # allow(span_op).to receive(:set_tag) + # allow(span_op).to receive(:set_error) + # failed! + # end + + # shared_examples "failed test span operation" do + # it do + # expect(span_op) + # .to have_received(:status=) + # .with(1) + # end + + # it do + # expect(span_op) + # .to have_received(:set_tag) + # .with( + # Datadog::CI::Ext::Test::TAG_STATUS, + # Datadog::CI::Ext::Test::Status::FAIL + # ) + # end + # end + + # context "when no exception is given" do + # subject(:failed!) { described_class.failed!(span_op) } + + # it_behaves_like "failed test span operation" + # it { expect(span_op).to_not have_received(:set_error) } + # end + + # context "when exception is given" do + # subject(:failed!) { described_class.failed!(span_op, exception) } + # let(:exception) { instance_double(StandardError) } + + # it_behaves_like "failed test span operation" + + # it do + # expect(span_op) + # .to have_received(:set_error) + # .with(exception) + # end + # end + # end + + # TODO: move to Span + # describe "::skipped!" do + # let(:span_op) { instance_double(Datadog::Tracing::SpanOperation) } + + # before do + # allow(span_op).to receive(:set_tag) + # allow(span_op).to receive(:set_error) + # skipped! + # end + + # shared_examples "skipped test span operation" do + # it do + # expect(span_op) + # .to have_received(:set_tag) + # .with( + # Datadog::CI::Ext::Test::TAG_STATUS, + # Datadog::CI::Ext::Test::Status::SKIP + # ) + # end + # end + + # context "when no exception is given" do + # subject(:skipped!) { described_class.skipped!(span_op) } + + # it_behaves_like "skipped test span operation" + # it { expect(span_op).to_not have_received(:set_error) } + # end + + # context "when exception is given" do + # subject(:skipped!) { described_class.skipped!(span_op, exception) } + # let(:exception) { instance_double(StandardError) } + + # it_behaves_like "skipped test span operation" + + # it do + # expect(span_op) + # .to have_received(:set_error) + # .with(exception) + # end + # end + # end end diff --git a/spec/support/tracer_helpers.rb b/spec/support/tracer_helpers.rb index 71583c6c..681b6e8a 100644 --- a/spec/support/tracer_helpers.rb +++ b/spec/support/tracer_helpers.rb @@ -22,20 +22,17 @@ def produce_test_trace( ) Timecop.freeze(start_time) - Datadog::CI::Recorder.trace( + Datadog::CI.trace_test( + test_name, + test_suite, + service, operation, { - span_options: { - resource: test_name, - service: service - }, framework: framework, framework_version: "1.0.0", - test_name: test_name, - test_suite: test_suite, test_type: "test" } - ) do |span| + ) do |test| if with_http_span Datadog::Tracing.trace("http-call", type: "http", service: "net-http") do |span, trace| span.set_tag("custom_tag", "custom_tag_value") @@ -48,11 +45,11 @@ def produce_test_trace( case result when "FAILED" - Datadog::CI::Recorder.failed!(span, exception) + test.failed!(exception) when "SKIPPED" - Datadog::CI::Recorder.skipped!(span, exception) + test.skipped!(exception) else - Datadog::CI::Recorder.passed!(span) + test.passed! end Timecop.travel(start_time + duration_seconds)