From 11856797facfd3cb19bad9bc426cc0e5a469d6e7 Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Mon, 4 Dec 2023 13:45:11 +0100 Subject: [PATCH] Make sure that suites, modules, session ids are integers --- .gitignore | 1 + lib/datadog/ci/test_visibility/serializers/base.rb | 10 +++++++--- sig/datadog/ci/test_visibility/serializers/base.rbs | 8 +++++--- .../ci/test_visibility/serializers/test_module_spec.rb | 4 ++-- .../test_visibility/serializers/test_session_spec.rb | 2 +- .../ci/test_visibility/serializers/test_suite_spec.rb | 6 +++--- .../ci/test_visibility/serializers/test_v2_spec.rb | 8 ++++---- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 100fdc5e..68740aeb 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ Gemfile-*.lock .envrc .ruby-version .DS_Store +/test.rb diff --git a/lib/datadog/ci/test_visibility/serializers/base.rb b/lib/datadog/ci/test_visibility/serializers/base.rb index 8c01f2bd..cbfc7e18 100644 --- a/lib/datadog/ci/test_visibility/serializers/base.rb +++ b/lib/datadog/ci/test_visibility/serializers/base.rb @@ -87,15 +87,15 @@ def parent_id end def test_session_id - @span.get_tag(Ext::Test::TAG_TEST_SESSION_ID) + to_integer(@span.get_tag(Ext::Test::TAG_TEST_SESSION_ID)) end def test_module_id - @span.get_tag(Ext::Test::TAG_TEST_MODULE_ID) + to_integer(@span.get_tag(Ext::Test::TAG_TEST_MODULE_ID)) end def test_suite_id - @span.get_tag(Ext::Test::TAG_TEST_SUITE_ID) + to_integer(@span.get_tag(Ext::Test::TAG_TEST_SUITE_ID)) end def type @@ -181,6 +181,10 @@ def time_nano(time) def duration_nano(duration) (duration * 1e9).to_i end + + def to_integer(value) + value.to_i if value + end end end end diff --git a/sig/datadog/ci/test_visibility/serializers/base.rbs b/sig/datadog/ci/test_visibility/serializers/base.rbs index d9c9280e..98e170fd 100644 --- a/sig/datadog/ci/test_visibility/serializers/base.rbs +++ b/sig/datadog/ci/test_visibility/serializers/base.rbs @@ -34,11 +34,11 @@ module Datadog def parent_id: () -> String - def test_session_id: () -> String? + def test_session_id: () -> Integer? - def test_module_id: () -> String? + def test_module_id: () -> Integer? - def test_suite_id: () -> String? + def test_suite_id: () -> Integer? def type: () -> nil @@ -75,6 +75,8 @@ module Datadog def time_nano: (Time time) -> Integer def duration_nano: (Float duration) -> Integer + def to_integer: (String? value) -> Integer? + def content_fields_count: () -> Integer end end diff --git a/spec/datadog/ci/test_visibility/serializers/test_module_spec.rb b/spec/datadog/ci/test_visibility/serializers/test_module_spec.rb index cde2aecc..421b6830 100644 --- a/spec/datadog/ci/test_visibility/serializers/test_module_spec.rb +++ b/spec/datadog/ci/test_visibility/serializers/test_module_spec.rb @@ -18,8 +18,8 @@ expect(content).to include( { - "test_session_id" => test_session_span.id.to_s, - "test_module_id" => test_module_span.id.to_s, + "test_session_id" => test_session_span.id, + "test_module_id" => test_module_span.id, "name" => "rspec.test_module", "service" => "rspec-test-suite", "type" => Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE, diff --git a/spec/datadog/ci/test_visibility/serializers/test_session_spec.rb b/spec/datadog/ci/test_visibility/serializers/test_session_spec.rb index c6940a9d..3855cd8c 100644 --- a/spec/datadog/ci/test_visibility/serializers/test_session_spec.rb +++ b/spec/datadog/ci/test_visibility/serializers/test_session_spec.rb @@ -18,7 +18,7 @@ expect(content).to include( { - "test_session_id" => test_session_span.id.to_s, + "test_session_id" => test_session_span.id, "name" => "rspec.test_session", "service" => "rspec-test-suite", "type" => Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION, diff --git a/spec/datadog/ci/test_visibility/serializers/test_suite_spec.rb b/spec/datadog/ci/test_visibility/serializers/test_suite_spec.rb index 20d4c7ae..095e421b 100644 --- a/spec/datadog/ci/test_visibility/serializers/test_suite_spec.rb +++ b/spec/datadog/ci/test_visibility/serializers/test_suite_spec.rb @@ -18,9 +18,9 @@ expect(content).to include( { - "test_session_id" => test_session_span.id.to_s, - "test_module_id" => test_module_span.id.to_s, - "test_suite_id" => test_suite_span.id.to_s, + "test_session_id" => test_session_span.id, + "test_module_id" => test_module_span.id, + "test_suite_id" => test_suite_span.id, "name" => "rspec.test_suite", "error" => 0, "service" => "rspec-test-suite", diff --git a/spec/datadog/ci/test_visibility/serializers/test_v2_spec.rb b/spec/datadog/ci/test_visibility/serializers/test_v2_spec.rb index cb9bdb01..7c18e056 100644 --- a/spec/datadog/ci/test_visibility/serializers/test_v2_spec.rb +++ b/spec/datadog/ci/test_visibility/serializers/test_v2_spec.rb @@ -27,9 +27,9 @@ "service" => "rspec-test-suite", "type" => "test", "resource" => "calculator_tests.test_add.run.0", - "test_session_id" => test_session_span.id.to_s, - "test_module_id" => test_module_span.id.to_s, - "test_suite_id" => test_suite_span.id.to_s + "test_session_id" => test_session_span.id, + "test_module_id" => test_module_span.id, + "test_suite_id" => test_suite_span.id } ) @@ -70,7 +70,7 @@ "service" => "rspec-test-suite", "type" => "test", "resource" => "calculator_tests.test_add.run.#{index}", - "test_session_id" => test_session_span.id.to_s + "test_session_id" => test_session_span.id } ) end