Skip to content

Commit

Permalink
store skippable tests as Set for faster checks
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Apr 15, 2024
1 parent f3cd615 commit 3030945
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
22 changes: 7 additions & 15 deletions lib/datadog/ci/itr/skippable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@

require_relative "../ext/transport"
require_relative "../ext/test"
require_relative "../utils/test_run"

module Datadog
module CI
module ITR
class Skippable
class Test
attr_reader :name, :suite

def initialize(name:, suite:)
@name = name
@suite = suite
end

def ==(other)
name == other.name && suite == other.suite
end
end

class Response
def initialize(http_response)
@http_response = http_response
Expand All @@ -38,13 +26,17 @@ def correlation_id
end

def tests
res = Set.new

payload.fetch("data", [])
.filter_map do |test_data|
.each do |test_data|
next unless test_data["type"] == Ext::Test::ITR_TEST_SKIPPING_MODE

attrs = test_data["attributes"] || {}
Test.new(name: attrs["name"], suite: attrs["suite"])
res << Utils::TestRun.test_full_name(attrs["name"], attrs["suite"])
end

res
end

private
Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/ci/utils/test_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def self.command

@command = "#{$0} #{ARGV.join(" ")}"
end

def self.test_full_name(test_name, suite)
"#{suite}.#{test_name}"
end
end
end
end
Expand Down
14 changes: 1 addition & 13 deletions sig/datadog/ci/itr/skippable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ module Datadog
@api: Datadog::CI::Transport::Api::Base?
@dd_env: String?

class Test
@name: String?

@suite: String?

attr_reader name: String?

attr_reader suite: String?

def initialize: (name: String?, suite: String?) -> void
end

class Response
@http_response: Datadog::Core::Transport::HTTP::Adapters::Net::Response?
@json: Hash[String, untyped]?
Expand All @@ -27,7 +15,7 @@ module Datadog

def correlation_id: () -> String?

def tests: () -> Array[Test]
def tests: () -> Set[String]

private

Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/utils/test_run.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Datadog
self.@command: String

def self.command: () -> String

def self.test_full_name: (String test_name, String test_suite) -> String
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions spec/datadog/ci/itr/skippable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@
it "parses the response" do
expect(response.ok?).to be true
expect(response.correlation_id).to eq("correlation_id_123")
expect(response.tests.first).to eq(
Datadog::CI::ITR::Skippable::Test.new(name: "test_name", suite: "test_suite_name")
)
expect(response.tests.first).to eq("test_suite_name.test_name")
end
end

Expand Down

0 comments on commit 3030945

Please sign in to comment.