Skip to content

Commit

Permalink
rename and reorganize some tracer_helpers; better specs for boolean m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
anmarchenko committed Jan 30, 2024
1 parent 11faef9 commit 8b1155e
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 150 deletions.
34 changes: 18 additions & 16 deletions spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,27 @@
end

it "creates test suite span" do
expect(test_suite_span).not_to be_nil
expect(test_suite_span.name).to eq("Datadog integration at spec/datadog/ci/contrib/cucumber/features/passing.feature")
expect(test_suite_span.service).to eq("jalapenos")
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_SPAN_KIND)).to eq(
expect(first_test_suite_span).not_to be_nil
expect(first_test_suite_span.name).to eq("Datadog integration at spec/datadog/ci/contrib/cucumber/features/passing.feature")
expect(first_test_suite_span.service).to eq("jalapenos")
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_SPAN_KIND)).to eq(
Datadog::CI::Ext::Test::SPAN_KIND_TEST
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK)).to eq(
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK)).to eq(
Datadog::CI::Contrib::Cucumber::Ext::FRAMEWORK
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK_VERSION)).to eq(
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK_VERSION)).to eq(
Datadog::CI::Contrib::Cucumber::Integration.version.to_s
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(Datadog::CI::Ext::Test::Status::PASS)
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(Datadog::CI::Ext::Test::Status::PASS)
end

it "connects scenario span to test session and test module" do
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID)).to eq(test_module_span.id.to_s)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_MODULE)).to eq(test_command)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID)).to eq(test_session_span.id.to_s)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(test_suite_span.id.to_s)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(test_suite_span.name)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(first_test_suite_span.id.to_s)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(first_test_suite_span.name)
end
end

Expand All @@ -213,10 +213,10 @@
Datadog::CI::Ext::Test::Status::FAIL
)

expect(test_suite_span.name).to eq(
expect(first_test_suite_span.name).to eq(
"Datadog integration - test failing features at spec/datadog/ci/contrib/cucumber/features/failing.feature"
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)

Expand Down Expand Up @@ -252,7 +252,7 @@
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(
"Datadog integration for parametrized tests at spec/datadog/ci/contrib/cucumber/features/with_parameters.feature"
)
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(test_suite_span.id.to_s)
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(first_test_suite_span.id.to_s)
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::PASS
)
Expand Down Expand Up @@ -316,8 +316,8 @@
end

it "marks test suite as failed" do
expect(test_suite_span).not_to be_nil
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(Datadog::CI::Ext::Test::Status::FAIL)
expect(first_test_suite_span).not_to be_nil
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(Datadog::CI::Ext::Test::Status::FAIL)
end

it "marks undefined cucumber scenario as failed" do
Expand Down Expand Up @@ -362,8 +362,10 @@
end

it "marks test suite as skipped" do
expect(test_suite_span).not_to be_nil
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(Datadog::CI::Ext::Test::Status::SKIP)
expect(first_test_suite_span).not_to be_nil
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::SKIP
)
end
end
end
22 changes: 11 additions & 11 deletions spec/datadog/ci/contrib/minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,21 +443,21 @@ def test_pass_other
end

it "creates a test suite span" do
expect(test_suite_span).not_to be_nil
expect(first_test_suite_span).not_to be_nil

expect(test_suite_span.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE)
expect(test_suite_span.name).to eq("SomeTest at spec/datadog/ci/contrib/minitest/instrumentation_spec.rb")
expect(first_test_suite_span.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE)
expect(first_test_suite_span.name).to eq("SomeTest at spec/datadog/ci/contrib/minitest/instrumentation_spec.rb")

expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_SPAN_KIND)).to eq(
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_SPAN_KIND)).to eq(
Datadog::CI::Ext::Test::SPAN_KIND_TEST
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK)).to eq(
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK)).to eq(
Datadog::CI::Contrib::Minitest::Ext::FRAMEWORK
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK_VERSION)).to eq(
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK_VERSION)).to eq(
Datadog::CI::Contrib::Minitest::Integration.version.to_s
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::PASS
)
end
Expand Down Expand Up @@ -489,7 +489,7 @@ def test_pass_other
expect(test_module_ids.first).to eq(test_module_span.id.to_s)

expect(test_suite_ids.count).to eq(1)
expect(test_suite_ids.first).to eq(test_suite_span.id.to_s)
expect(test_suite_ids.first).to eq(first_test_suite_span.id.to_s)
end
end

Expand All @@ -516,7 +516,7 @@ def test_fail
expect(test_module_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
end
Expand Down Expand Up @@ -704,8 +704,8 @@ def test_2
end

it "marks test suite as skipped" do
expect(test_suite_span).not_to be_nil
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(Datadog::CI::Ext::Test::Status::SKIP)
expect(first_test_suite_span).not_to be_nil
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(Datadog::CI::Ext::Test::Status::SKIP)
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def with_new_rspec_environment
end

expect(test_spans).to have(1).items
expect(tracer_spans).to have(1).items
expect(custom_spans).to have(1).items

tracer_spans.each do |span|
custom_spans.each do |span|
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::Distributed::TAG_ORIGIN))
.to eq(Datadog::CI::Ext::Test::CONTEXT_ORIGIN)
end
Expand Down Expand Up @@ -477,10 +477,10 @@ def rspec_session_run(with_failed_test: false, with_shared_test: false)
it "creates test suite span" do
spec = rspec_session_run

expect(test_suite_span).not_to be_nil
expect(first_test_suite_span).not_to be_nil

expect(test_suite_span.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE)
expect(test_suite_span.name).to eq("SomeTest at #{spec.file_path}")
expect(first_test_suite_span.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE)
expect(first_test_suite_span.name).to eq("SomeTest at #{spec.file_path}")

expect(test_module_span.get_tag(Datadog::CI::Ext::Test::TAG_SPAN_KIND)).to eq(
Datadog::CI::Ext::Test::SPAN_KIND_TEST
Expand All @@ -501,7 +501,7 @@ def rspec_session_run(with_failed_test: false, with_shared_test: false)

expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID)).to eq(test_session_span.id.to_s)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID)).to eq(test_module_span.id.to_s)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(test_suite_span.id.to_s)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(first_test_suite_span.id.to_s)
end

context "with failures" do
Expand All @@ -526,8 +526,8 @@ def rspec_session_run(with_failed_test: false, with_shared_test: false)
it "creates test suite span with failed state" do
rspec_session_run(with_failed_test: true)

expect(test_suite_span).not_to be_nil
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
expect(first_test_suite_span).not_to be_nil
expect(first_test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
end
Expand All @@ -549,7 +549,7 @@ def rspec_session_run(with_failed_test: false, with_shared_test: false)
end

test_spans.each do |test_span|
expect(test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(test_suite_span.id.to_s)
expect(test_span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(first_test_suite_span.id.to_s)
end
end
end
Expand Down
32 changes: 8 additions & 24 deletions spec/datadog/ci/span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@
allow(tracer_span).to receive(:get_tag).with("test.status").and_return("pass")
end

it "returns true" do
expect(span.passed?).to eq(true)
end
it { is_expected.to be_passed }
end

context "when status is not PASS" do
before do
allow(tracer_span).to receive(:get_tag).with("test.status").and_return("fail")
end

it "returns false" do
expect(span.passed?).to eq(false)
end
it { is_expected.not_to be_passed }
end
end

Expand All @@ -36,19 +32,15 @@
allow(tracer_span).to receive(:get_tag).with("test.status").and_return("fail")
end

it "returns true" do
expect(span.failed?).to eq(true)
end
it { is_expected.to be_failed }
end

context "when status is not FAIL" do
before do
allow(tracer_span).to receive(:get_tag).with("test.status").and_return("pass")
end

it "returns false" do
expect(span.failed?).to eq(false)
end
it { is_expected.not_to be_failed }
end
end

Expand All @@ -58,19 +50,15 @@
allow(tracer_span).to receive(:get_tag).with("test.status").and_return("skip")
end

it "returns true" do
expect(span.skipped?).to eq(true)
end
it { is_expected.to be_skipped }
end

context "when status is not SKIP" do
before do
allow(tracer_span).to receive(:get_tag).with("test.status").and_return("pass")
end

it "returns false" do
expect(span.skipped?).to eq(false)
end
it { is_expected.not_to be_skipped }
end
end

Expand All @@ -80,19 +68,15 @@
allow(tracer_span).to receive(:get_tag).with("test.status").and_return(nil)
end

it "returns true" do
expect(span.undefined?).to eq(true)
end
it { is_expected.to be_undefined }
end

context "when status is not nil" do
before do
allow(tracer_span).to receive(:get_tag).with("test.status").and_return("pass")
end

it "returns false" do
expect(span.undefined?).to eq(false)
end
it { is_expected.not_to be_undefined }
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end

context "with a suite span" do
let(:ci_span) { test_suite_span }
let(:ci_span) { first_test_suite_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSuite) }
end

Expand All @@ -36,7 +36,7 @@
end

context "with a http request span" do
let(:ci_span) { first_other_span }
let(:ci_span) { first_custom_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::Span) }
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/datadog/ci/test_visibility/serializers/span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
end

include_context "citestcycle serializer" do
subject { described_class.new(trace_for_span(first_other_span), first_other_span) }
subject { described_class.new(trace_for_span(first_custom_span), first_custom_span) }
end

describe "#to_msgpack" do
Expand All @@ -22,7 +22,7 @@
expect(content).to include(
{
"trace_id" => first_test_span.trace_id,
"span_id" => first_other_span.id,
"span_id" => first_custom_span.id,
"parent_id" => first_test_span.id,
"name" => "http-call",
"service" => "net-http",
Expand Down Expand Up @@ -50,7 +50,7 @@
before do
produce_test_trace(with_http_span: true)

first_other_span.name = nil
first_custom_span.name = nil
end

it { is_expected.not_to be_valid }
Expand Down
32 changes: 14 additions & 18 deletions spec/datadog/ci/test_visibility/serializers/test_module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,43 @@
end

describe "#valid?" do
context "test_session_id" do
before do
produce_test_session_trace
end
before do
produce_test_session_trace
end

context "test_session_id" do
context "when test_session_id is not nil" do
it "returns true" do
expect(subject.valid?).to eq(true)
end
it { is_expected.to be_valid }
end

context "when test_session_id is nil" do
before do
test_module_span.clear_tag("_test.session_id")
subject.valid?
end

it "returns false" do
expect(subject.valid?).to eq(false)
it { is_expected.not_to be_valid }

it "returns a correct validation error" do
expect(subject.validation_errors["test_session_id"]).to include("is required")
end
end
end

context "test_module_id" do
before do
produce_test_session_trace
end

context "when test_module_id is not nil" do
it "returns true" do
expect(subject.valid?).to eq(true)
end
it { is_expected.to be_valid }
end

context "when test_module_id is nil" do
before do
test_module_span.clear_tag("_test.module_id")
subject.valid?
end

it "returns false" do
expect(subject.valid?).to eq(false)
it { is_expected.not_to be_valid }

it "returns a correct validation error" do
expect(subject.validation_errors["test_module_id"]).to include("is required")
end
end
Expand Down
Loading

0 comments on commit 8b1155e

Please sign in to comment.