Skip to content

Commit

Permalink
add #require_git? method to RemoteSettingsApi::Response
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Apr 11, 2024
1 parent 9fab5aa commit 77c51fb
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
12 changes: 5 additions & 7 deletions lib/datadog/ci/itr/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

require_relative "../git/local_repository"

require_relative "../utils/parsing"

require_relative "coverage/event"

module Datadog
Expand All @@ -32,13 +34,13 @@ def initialize(
def configure(remote_configuration, test_session)
Datadog.logger.debug("Configuring ITR Runner with remote configuration: #{remote_configuration}")

@enabled = convert_to_bool(
@enabled = Utils::Parsing.convert_to_bool(
remote_configuration.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_ITR_ENABLED_KEY, false)
)
@test_skipping_enabled = @enabled && convert_to_bool(
@test_skipping_enabled = @enabled && Utils::Parsing.convert_to_bool(
remote_configuration.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_TESTS_SKIPPING_KEY, false)
)
@code_coverage_enabled = @enabled && convert_to_bool(
@code_coverage_enabled = @enabled && Utils::Parsing.convert_to_bool(
remote_configuration.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_CODE_COVERAGE_KEY, false)
)

Expand Down Expand Up @@ -121,10 +123,6 @@ def load_datadog_cov!
@code_coverage_enabled = false
end

def convert_to_bool(value)
value.to_s == "true"
end

def ensure_test_source_covered(test_source_file, coverage)
absolute_test_source_file_path = File.join(Git::LocalRepository.root, test_source_file)
return if coverage.key?(absolute_test_source_file_path)
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog/ci/transport/remote_settings_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "datadog/core/environment/identity"

require_relative "../ext/transport"
require_relative "../utils/parsing"

module Datadog
module CI
Expand Down Expand Up @@ -39,6 +40,10 @@ def payload
end
end

def require_git?
Utils::Parsing.convert_to_bool(payload[Ext::Transport::DD_API_SETTINGS_RESPONSE_REQUIRE_GIT_KEY])
end

private

def default_payload
Expand Down
16 changes: 16 additions & 0 deletions lib/datadog/ci/utils/parsing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "open3"
require "pathname"

module Datadog
module CI
module Utils
module Parsing
def self.convert_to_bool(value)
value.to_s.downcase == "true"
end
end
end
end
end
2 changes: 0 additions & 2 deletions sig/datadog/ci/itr/runner.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module Datadog

def coverage_collector: () -> Datadog::CI::ITR::Coverage::DDCov?

def convert_to_bool: (untyped value) -> bool

def load_datadog_cov!: () -> void

def write: (Datadog::CI::ITR::Coverage::Event event) -> void
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/transport/remote_settings_api.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module Datadog

def payload: () -> Hash[String, untyped]

def require_git?: () -> bool

private

def default_payload: () -> Hash[String, untyped]
Expand Down
9 changes: 9 additions & 0 deletions sig/datadog/ci/utils/parsing.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Datadog
module CI
module Utils
module Parsing
def self.convert_to_bool: (untyped value) -> bool
end
end
end
end
18 changes: 16 additions & 2 deletions spec/datadog/ci/transport/remote_settings_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,31 @@
"code_coverage" => true,
"tests_skipping" => false,
"itr_enabled" => true,
"require_git" => false
"require_git" => require_git
}
}
}.to_json
)
end
let(:require_git) { false }

it "parses the response" do
expect(response.ok?).to be true
expect(response.payload).to eq({
"code_coverage" => true,
"tests_skipping" => false,
"itr_enabled" => true,
"require_git" => false
"require_git" => require_git
})
expect(response.require_git?).to be false
end

context "when git is required" do
let(:require_git) { "True" }

it "parses the response" do
expect(response.require_git?).to be true
end
end
end

Expand All @@ -103,6 +113,7 @@
it "parses the response" do
expect(response.ok?).to be false
expect(response.payload).to eq("itr_enabled" => false)
expect(response.require_git?).to be false
end
end

Expand All @@ -122,6 +133,7 @@
it "parses the response" do
expect(response.ok?).to be true
expect(response.payload).to eq("itr_enabled" => false)
expect(response.require_git?).to be false
end
end

Expand All @@ -144,6 +156,7 @@
it "parses the response" do
expect(response.ok?).to be true
expect(response.payload).to eq("itr_enabled" => false)
expect(response.require_git?).to be false
end
end
end
Expand All @@ -154,6 +167,7 @@
it "returns an empty response" do
expect(response.ok?).to be false
expect(response.payload).to eq("itr_enabled" => false)
expect(response.require_git?).to be false
end
end
end
Expand Down

0 comments on commit 77c51fb

Please sign in to comment.