Skip to content

Commit

Permalink
add convenience method CI.start_test
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Nov 3, 2023
1 parent 30dfdd0 commit 5382c89
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/datadog/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ module Datadog
# @public_api
module CI
class << self
# Trace a test run
# @public_api
def trace_test(test_name, service_name: nil, operation_name: "test", tags: {}, &block)
recorder.trace_test(test_name, service_name: service_name, operation_name: operation_name, tags: tags, &block)
end

# Start a test run trace.
# @public_api
def start_test(test_name, service_name: nil, operation_name: "test", tags: {})
recorder.trace_test(test_name, service_name: service_name, operation_name: operation_name, tags: tags)
end

def trace(span_type, span_name, tags: {}, &block)
recorder.trace(span_type, span_name, tags: tags, &block)
end
Expand Down
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 @@ -28,7 +28,7 @@ def bind_events(config)
end

def on_test_case_started(event)
@current_feature_span = CI.trace_test(
@current_feature_span = CI.start_test(
event.test_case.name,
tags: {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
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 @@ -19,7 +19,7 @@ def before_setup
path, = method(name).source_location
test_suite = Pathname.new(path.to_s).relative_path_from(Pathname.pwd).to_s

test_span = CI.trace_test(
test_span = CI.start_test(
test_name,
tags: {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Datadog
module CI
def self.trace_test: (String span_name, ?service_name: String?, ?operation_name: String, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

def self.start_test: (String span_name, ?service_name: String?, ?operation_name: String, ?tags: Hash[untyped, untyped]) -> Datadog::CI::Span

def self.trace: (String span_type, String span_name, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

def self.components: () -> Datadog::CI::Configuration::Components
Expand Down
24 changes: 24 additions & 0 deletions spec/datadog/ci_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@
it { is_expected.to be(ci_test) }
end

describe "#start_test" do
subject(:start_test) { described_class.start_test(test_name, **options) }

let(:test_name) { "test name" }
let(:options) do
{
service_name: "my-serivce",
operation_name: "rspec.example",
tags: {"foo" => "bar"}
}
end

let(:recorder) { instance_double(Datadog::CI::Recorder) }
let(:ci_test) { instance_double(Datadog::CI::Span) }

before do
allow(Datadog::CI).to receive(:recorder).and_return(recorder)

allow(recorder).to receive(:trace_test).with(test_name, **options).and_return(ci_test)
end

it { is_expected.to be(ci_test) }
end

describe "::trace" do
subject(:trace) { described_class.trace(span_type, span_name, **options, &block) }

Expand Down

0 comments on commit 5382c89

Please sign in to comment.