-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b48270f
commit 3f10e27
Showing
10 changed files
with
248 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "base" | ||
require_relative "../../ext/test" | ||
|
||
module Datadog | ||
module CI | ||
module TestVisibility | ||
module Serializers | ||
class TestModule < Base | ||
CONTENT_FIELDS = [ | ||
"test_session_id", | ||
"test_module_id", | ||
"name", "resource", "service", | ||
"error", "start", "duration", | ||
"meta", "metrics", | ||
"type" => "span_type" | ||
].freeze | ||
|
||
CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS) | ||
|
||
REQUIRED_FIELDS = [ | ||
"test_session_id", | ||
"test_module_id", | ||
"error", | ||
"name", | ||
"resource", | ||
"start", | ||
"duration" | ||
].freeze | ||
|
||
def content_fields | ||
CONTENT_FIELDS | ||
end | ||
|
||
def content_map_size | ||
CONTENT_MAP_SIZE | ||
end | ||
|
||
def type | ||
Ext::AppTypes::TYPE_TEST_MODULE | ||
end | ||
|
||
def name | ||
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_module" | ||
end | ||
|
||
def resource | ||
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_module.#{@span.get_tag(Ext::Test::TAG_MODULE)}" | ||
end | ||
|
||
private | ||
|
||
def required_fields | ||
REQUIRED_FIELDS | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
sig/datadog/ci/test_visibility/serializers/test_module.rbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Datadog | ||
module CI | ||
module TestVisibility | ||
module Serializers | ||
class TestModule < Base | ||
CONTENT_FIELDS: Array[String | Hash[String, String]] | ||
CONTENT_MAP_SIZE: Integer | ||
REQUIRED_FIELDS: Array[String] | ||
|
||
def content_fields: () -> Array[String | Hash[String, String]] | ||
def content_map_size: () -> Integer | ||
|
||
def type: () -> ::String | ||
|
||
def name: () -> ::String | ||
|
||
def resource: () -> ::String | ||
|
||
private | ||
|
||
def required_fields: () -> Array[String] | ||
end | ||
end | ||
end | ||
end | ||
end |
106 changes: 106 additions & 0 deletions
106
spec/datadog/ci/test_visibility/serializers/test_module_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
RSpec.describe Datadog::CI::TestVisibility::Serializers::TestModule do | ||
include_context "CI mode activated" do | ||
let(:integration_name) { :rspec } | ||
end | ||
|
||
include_context "Test visibility event serialized" do | ||
subject { described_class.new(trace_for_span(test_module_span), test_module_span) } | ||
end | ||
|
||
describe "#to_msgpack" do | ||
context "traced a single test execution with Recorder" do | ||
before do | ||
produce_test_session_trace | ||
end | ||
|
||
it "serializes test event to messagepack" do | ||
expect_event_header(type: Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE) | ||
|
||
expect(content).to include( | ||
{ | ||
"test_session_id" => test_session_span.id.to_s, | ||
"test_module_id" => test_module_span.id.to_s, | ||
"name" => "rspec.test_module", | ||
"service" => "rspec-test-suite", | ||
"type" => Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE, | ||
"resource" => "rspec.test_module.arithmetic" | ||
} | ||
) | ||
|
||
expect(meta).to include( | ||
{ | ||
"test.command" => test_command, | ||
"test.module" => "arithmetic", | ||
"test.framework" => "rspec", | ||
"test.framework_version" => "1.0.0", | ||
"test.type" => "test", | ||
"test.status" => "pass", | ||
"_dd.origin" => "ciapp-test" | ||
} | ||
) | ||
|
||
expect(meta["_test.session_id"]).to be_nil | ||
expect(meta["_test.module_id"]).to be_nil | ||
end | ||
end | ||
|
||
context "trace a failed test" do | ||
before do | ||
produce_test_session_trace(result: "FAILED", exception: StandardError.new("1 + 2 are not equal to 5")) | ||
end | ||
|
||
it "has error" do | ||
expect_event_header(type: Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE) | ||
|
||
expect(content).to include({"error" => 1}) | ||
expect(meta).to include({"test.status" => "fail"}) | ||
end | ||
end | ||
end | ||
|
||
describe "#valid?" do | ||
context "test_session_id" do | ||
before do | ||
produce_test_session_trace | ||
end | ||
|
||
context "when test_session_id is not nil" do | ||
it "returns true" do | ||
expect(subject.valid?).to eq(true) | ||
end | ||
end | ||
|
||
context "when test_session_id is nil" do | ||
before do | ||
test_module_span.clear_tag("_test.session_id") | ||
end | ||
|
||
it "returns false" do | ||
expect(subject.valid?).to eq(false) | ||
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 | ||
end | ||
|
||
context "when test_module_id is nil" do | ||
before do | ||
test_module_span.clear_tag("_test.module_id") | ||
end | ||
|
||
it "returns false" do | ||
expect(subject.valid?).to eq(false) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters