diff --git a/lib/datadog/ci/utils/parsing.rb b/lib/datadog/ci/utils/parsing.rb index e519935e..9c3e1bd4 100644 --- a/lib/datadog/ci/utils/parsing.rb +++ b/lib/datadog/ci/utils/parsing.rb @@ -8,7 +8,8 @@ module CI module Utils module Parsing def self.convert_to_bool(value) - value.to_s.downcase == "true" + normalized_value = value.to_s.downcase + normalized_value == "true" || normalized_value == "1" end end end diff --git a/spec/datadog/ci/utils/parsing_spec.rb b/spec/datadog/ci/utils/parsing_spec.rb new file mode 100644 index 00000000..3dc9aeaa --- /dev/null +++ b/spec/datadog/ci/utils/parsing_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require_relative "../../../../lib/datadog/ci/utils/parsing" + +RSpec.describe Datadog::CI::Utils::Parsing do + describe ".convert_to_bool" do + subject(:convert_to_bool) { described_class.convert_to_bool(value) } + + context "when the value is a boolean" do + context "and the value is true" do + let(:value) { true } + + it { is_expected.to be true } + end + + context "and the value is false" do + let(:value) { false } + + it { is_expected.to be false } + end + end + + context "when the value is a string" do + context "and the value is 'true'" do + let(:value) { "true" } + + it { is_expected.to be true } + end + + context "and the value is 'false'" do + let(:value) { "false" } + + it { is_expected.to be false } + end + + context "and the value is '1'" do + let(:value) { "1" } + + it { is_expected.to be true } + end + + context "and the value is '0'" do + let(:value) { "0" } + + it { is_expected.to be false } + end + + context "and the value is 'TRUE'" do + let(:value) { "TRUE" } + + it { is_expected.to be true } + end + + context "and the value is 'FALSE'" do + let(:value) { "FALSE" } + + it { is_expected.to be false } + end + end + + context "when the value is an integer" do + context "and the value is 1" do + let(:value) { 1 } + + it { is_expected.to be true } + end + + context "and the value is 0" do + let(:value) { 0 } + + it { is_expected.to be false } + end + end + end +end