Skip to content

Commit

Permalink
add Utils::Configuration.service_name_provided_by_user? global function
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Dec 13, 2024
1 parent c2b203f commit dc8a625
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/datadog/ci/utils/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module Configuration
def self.fetch_service_name(default)
Datadog.configuration.service_without_fallback || CI::Git::LocalRepository.repository_name || default
end

def self.service_name_provided_by_user?
!!Datadog.configuration.service_without_fallback
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/utils/configuration.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Datadog
module Utils
module Configuration
def self.fetch_service_name: (String default) -> String

def self.service_name_provided_by_user?: () -> bool
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/datadog/ci/utils/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,24 @@
end
end
end

describe ".service_name_provided_by_user?" do
subject { described_class.service_name_provided_by_user? }

before do
allow(::Datadog.configuration).to receive(:service_without_fallback).and_return(service)
end

context "when service is set in Datadog config" do
let(:service) { "service_without_fallback" }

it { is_expected.to be true }
end

context "when service is not set" do
let(:service) { nil }

it { is_expected.to be false }
end
end
end

0 comments on commit dc8a625

Please sign in to comment.