From 112e8e8eb9e13a118975d01672b63716f41bae29 Mon Sep 17 00:00:00 2001 From: Furkan Ayhan Date: Fri, 14 Oct 2022 14:22:50 +0200 Subject: [PATCH 1/2] Add expand syntax to CI config This is the first step of implementing the raw variable support to CI config. The changes are behind the FF ci_raw_variables_in_yaml_config. In `YamlProcessor::Result#root_variables` and `Entry::Variable`, I used `YamlProcessor::FeatureFlags.enabled?`. So, I could only call these within the scope of `YamlProcessor::FeatureFlags.with_actor`. However, we call `root_variables` outside of the scope, so in this commit, I moved `root_variables` into a getter method and now it is calculated with the object instance. --- .../ci_raw_variables_in_yaml_config.yml | 8 ++ lib/gitlab/ci/config/entry/processable.rb | 1 + lib/gitlab/ci/config/entry/root.rb | 2 +- lib/gitlab/ci/config/entry/variable.rb | 28 ++++++- lib/gitlab/ci/variables/collection/item.rb | 5 +- lib/gitlab/ci/yaml_processor/result.rb | 7 +- .../ci/config/entry/processable_spec.rb | 25 +++++- spec/lib/gitlab/ci/config/entry/root_spec.rb | 29 +++++++ .../gitlab/ci/config/entry/variable_spec.rb | 82 +++++++++++++++++++ .../ci/variables/collection/item_spec.rb | 6 +- spec/lib/gitlab/ci/yaml_processor_spec.rb | 61 ++++++++++++++ 11 files changed, 246 insertions(+), 8 deletions(-) create mode 100644 config/feature_flags/development/ci_raw_variables_in_yaml_config.yml diff --git a/config/feature_flags/development/ci_raw_variables_in_yaml_config.yml b/config/feature_flags/development/ci_raw_variables_in_yaml_config.yml new file mode 100644 index 00000000000000..ab135526c0bb5d --- /dev/null +++ b/config/feature_flags/development/ci_raw_variables_in_yaml_config.yml @@ -0,0 +1,8 @@ +--- +name: ci_raw_variables_in_yaml_config +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/98420 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/375034 +milestone: '15.6' +type: development +group: group::pipeline authoring +default_enabled: false diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb index 2d2032b1d8c5db..e0a052ffdfddf5 100644 --- a/lib/gitlab/ci/config/entry/processable.rb +++ b/lib/gitlab/ci/config/entry/processable.rb @@ -60,6 +60,7 @@ module Processable entry :variables, ::Gitlab::Ci::Config::Entry::Variables, description: 'Environment variables available for this job.', + metadata: { allowed_value_data: %i[value expand] }, inherit: false entry :inherit, ::Gitlab::Ci::Config::Entry::Inherit, diff --git a/lib/gitlab/ci/config/entry/root.rb b/lib/gitlab/ci/config/entry/root.rb index 1d7d8617c74780..a30e6a0d9c3717 100644 --- a/lib/gitlab/ci/config/entry/root.rb +++ b/lib/gitlab/ci/config/entry/root.rb @@ -50,7 +50,7 @@ class Root < ::Gitlab::Config::Entry::Node entry :variables, Entry::Variables, description: 'Environment variables that will be used.', - metadata: { allowed_value_data: %i[value description], allow_array_value: true }, + metadata: { allowed_value_data: %i[value description expand], allow_array_value: true }, reserved: true entry :stages, Entry::Stages, diff --git a/lib/gitlab/ci/config/entry/variable.rb b/lib/gitlab/ci/config/entry/variable.rb index 54c153c8b07dfb..a606cd3f26fa30 100644 --- a/lib/gitlab/ci/config/entry/variable.rb +++ b/lib/gitlab/ci/config/entry/variable.rb @@ -48,6 +48,9 @@ def applies_to?(config) validates :key, alphanumeric: true validates :config_value, alphanumeric: true, allow_nil: false, if: :config_value_defined? validates :config_description, alphanumeric: true, allow_nil: false, if: :config_description_defined? + validates :config_expand, boolean: true, + allow_nil: false, + if: -> { ci_raw_variables_in_yaml_config_enabled? && config_expand_defined? } validate do allowed_value_data = Array(opt(:allowed_value_data)) @@ -67,7 +70,18 @@ def value end def value_with_data - { value: value, description: config_description }.compact + if ci_raw_variables_in_yaml_config_enabled? + { + value: value, + description: config_description, + raw: (!config_expand if config_expand_defined?) + }.compact + else + { + value: value, + description: config_description + }.compact + end end def config_value @@ -78,6 +92,10 @@ def config_description @config[:description] end + def config_expand + @config[:expand] + end + def config_value_defined? config.key?(:value) end @@ -85,6 +103,14 @@ def config_value_defined? def config_description_defined? config.key?(:description) end + + def config_expand_defined? + config.key?(:expand) + end + + def ci_raw_variables_in_yaml_config_enabled? + YamlProcessor::FeatureFlags.enabled?(:ci_raw_variables_in_yaml_config) + end end class ComplexArrayVariable < ComplexVariable diff --git a/lib/gitlab/ci/variables/collection/item.rb b/lib/gitlab/ci/variables/collection/item.rb index 45faf4f63ebb66..6cd34170abe8ae 100644 --- a/lib/gitlab/ci/variables/collection/item.rb +++ b/lib/gitlab/ci/variables/collection/item.rb @@ -10,7 +10,10 @@ class Item VARIABLES_REGEXP = /\$\$|%%|\$(?[a-zA-Z_][a-zA-Z0-9_]*)|\${\g?}|%\g%/.freeze.freeze VARIABLE_REF_CHARS = %w[$ %].freeze - def initialize(key:, value:, public: true, file: false, masked: false, raw: false) + # We accept additional parameters with `args` because `description` and `value_options` are sent + # from `Entry::Variable#value_with_data`. However, we ignore them because they are just used for + # the prefill-variables feature and not a real variable attribute. + def initialize(key:, value:, public: true, file: false, masked: false, raw: false, **args) raise ArgumentError, "`#{key}` must be of type String or nil value, while it was: #{value.class}" unless value.is_a?(String) || value.nil? diff --git a/lib/gitlab/ci/yaml_processor/result.rb b/lib/gitlab/ci/yaml_processor/result.rb index 4063bd870337a8..37d3e8900e5c35 100644 --- a/lib/gitlab/ci/yaml_processor/result.rb +++ b/lib/gitlab/ci/yaml_processor/result.rb @@ -64,7 +64,12 @@ def config_metadata private def assign_valid_attributes - @root_variables = transform_to_array(@ci_config.variables) + @root_variables = if YamlProcessor::FeatureFlags.enabled?(:ci_raw_variables_in_yaml_config) + transform_to_array(@ci_config.variables_with_data) + else + transform_to_array(@ci_config.variables) + end + @root_variables_with_data = @ci_config.variables_with_data @stages = @ci_config.stages diff --git a/spec/lib/gitlab/ci/config/entry/processable_spec.rb b/spec/lib/gitlab/ci/config/entry/processable_spec.rb index ad90dd59585500..052bcdacd0f4d5 100644 --- a/spec/lib/gitlab/ci/config/entry/processable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/processable_spec.rb @@ -208,7 +208,7 @@ def self.name it 'reports error about variable' do expect(entry.errors) - .to include 'variables:var2 config must be a string' + .to include 'variables:var2 config uses invalid data keys: description' end end end @@ -447,6 +447,29 @@ def self.name ) end end + + context 'when variables have "expand" data' do + let(:config) do + { + script: 'echo', + variables: { 'VAR1' => 'val 1', + 'VAR2' => { value: 'val 2', expand: false }, + 'VAR3' => { value: 'val 3', expand: true } } + } + end + + it 'returns correct value' do + expect(entry.value).to eq( + name: :rspec, + stage: 'test', + only: { refs: %w[branches tags] }, + job_variables: { 'VAR1' => { value: 'val 1' }, + 'VAR2' => { value: 'val 2', raw: true }, + 'VAR3' => { value: 'val 3', raw: false } }, + root_variables_inheritance: true + ) + end + end end end end diff --git a/spec/lib/gitlab/ci/config/entry/root_spec.rb b/spec/lib/gitlab/ci/config/entry/root_spec.rb index a55e13e7c2d9eb..085293d7368b96 100644 --- a/spec/lib/gitlab/ci/config/entry/root_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/root_spec.rb @@ -316,6 +316,35 @@ end end end + + context 'when variables have "expand" data' do + let(:hash) do + { + variables: { 'VAR1' => 'val 1', + 'VAR2' => { value: 'val 2', expand: false }, + 'VAR3' => { value: 'val 3', expand: true } }, + rspec: { script: 'rspec' } + } + end + + before do + root.compose! + end + + it 'returns correct value' do + expect(root.variables_entry.value_with_data).to eq( + 'VAR1' => { value: 'val 1' }, + 'VAR2' => { value: 'val 2', raw: true }, + 'VAR3' => { value: 'val 3', raw: false } + ) + + expect(root.variables_value).to eq( + 'VAR1' => 'val 1', + 'VAR2' => 'val 2', + 'VAR3' => 'val 3' + ) + end + end end context 'when configuration is not valid' do diff --git a/spec/lib/gitlab/ci/config/entry/variable_spec.rb b/spec/lib/gitlab/ci/config/entry/variable_spec.rb index 076a5b32e92ba6..9afd3df350b6f8 100644 --- a/spec/lib/gitlab/ci/config/entry/variable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/variable_spec.rb @@ -194,6 +194,88 @@ end end end + + context 'when config is a hash with expand' do + let(:config) { { value: 'value', expand: false } } + + context 'when metadata allowed_value_data is not provided' do + describe '#valid?' do + it { is_expected.not_to be_valid } + end + + describe '#errors' do + subject(:errors) { entry.errors } + + it { is_expected.to include 'var1 config must be a string' } + end + end + + context 'when metadata allowed_value_data is (value, expand)' do + let(:metadata) { { allowed_value_data: %i[value expand] } } + + describe '#valid?' do + it { is_expected.to be_valid } + end + + describe '#value' do + subject(:value) { entry.value } + + it { is_expected.to eq('value') } + end + + describe '#value_with_data' do + subject(:value_with_data) { entry.value_with_data } + + it { is_expected.to eq(value: 'value', raw: true) } + + context 'when the FF ci_raw_variables_in_yaml_config is disabled' do + before do + stub_feature_flags(ci_raw_variables_in_yaml_config: false) + end + + it { is_expected.to eq(value: 'value') } + end + end + + context 'when config expand is true' do + let(:config) { { value: 'value', expand: true } } + + describe '#value_with_data' do + subject(:value_with_data) { entry.value_with_data } + + it { is_expected.to eq(value: 'value', raw: false) } + end + end + + context 'when config expand is a string' do + let(:config) { { value: 'value', expand: "true" } } + + describe '#valid?' do + it { is_expected.not_to be_valid } + end + + describe '#errors' do + subject(:errors) { entry.errors } + + it { is_expected.to include 'var1 config expand should be a boolean value' } + end + end + end + + context 'when metadata allowed_value_data is (value, xyz)' do + let(:metadata) { { allowed_value_data: %i[value xyz] } } + + describe '#valid?' do + it { is_expected.not_to be_valid } + end + + describe '#errors' do + subject(:errors) { entry.errors } + + it { is_expected.to include 'var1 config uses invalid data keys: expand' } + end + end + end end describe 'ComplexArrayVariable' do diff --git a/spec/lib/gitlab/ci/variables/collection/item_spec.rb b/spec/lib/gitlab/ci/variables/collection/item_spec.rb index 9443bf6d6d5765..87f9424ec53c21 100644 --- a/spec/lib/gitlab/ci/variables/collection/item_spec.rb +++ b/spec/lib/gitlab/ci/variables/collection/item_spec.rb @@ -13,9 +13,9 @@ describe '.new' do context 'when unknown keyword is specified' do - it 'raises error' do - expect { described_class.new(key: variable_key, value: 'abc', files: true) } - .to raise_error ArgumentError, 'unknown keyword: :files' + it 'ignores the parameter' do + expect { described_class.new(key: variable_key, value: 'abc', description: 'hello') } + .not_to raise_error end end diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index ebf8422489e7e3..dabe6e26f63376 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -1071,6 +1071,7 @@ module Ci let(:build) { execute.builds.first } let(:job_variables) { build[:job_variables] } + let(:root_variables) { execute.root_variables } let(:root_variables_inheritance) { build[:root_variables_inheritance] } context 'when global variables are defined' do @@ -1193,6 +1194,66 @@ module Ci expect(root_variables_inheritance).to eq(true) end end + + context 'when variables have data other than value' do + let(:config) do + <<~YAML + variables: + VAR1: value1 + VAR2: + value: value2 + description: description2 + VAR3: + value: value3 + expand: false + + rspec: + script: rspec + variables: + VAR4: value4 + VAR5: + value: value5 + expand: false + VAR6: + value: value6 + expand: true + YAML + end + + it 'returns variables' do + expect(job_variables).to contain_exactly( + { key: 'VAR4', value: 'value4' }, + { key: 'VAR5', value: 'value5', raw: true }, + { key: 'VAR6', value: 'value6', raw: false } + ) + + expect(execute.root_variables).to contain_exactly( + { key: 'VAR1', value: 'value1' }, + { key: 'VAR2', value: 'value2', description: 'description2' }, + { key: 'VAR3', value: 'value3', raw: true } + ) + end + + context 'when the FF ci_raw_variables_in_yaml_config is disabled' do + before do + stub_feature_flags(ci_raw_variables_in_yaml_config: false) + end + + it 'returns variables without description and raw' do + expect(job_variables).to contain_exactly( + { key: 'VAR4', value: 'value4' }, + { key: 'VAR5', value: 'value5' }, + { key: 'VAR6', value: 'value6' } + ) + + expect(execute.root_variables).to contain_exactly( + { key: 'VAR1', value: 'value1' }, + { key: 'VAR2', value: 'value2' }, + { key: 'VAR3', value: 'value3' } + ) + end + end + end end context 'when using `extends`' do -- GitLab From 303278164d3066fab25acf02bbcff2de266351b9 Mon Sep 17 00:00:00 2001 From: Furkan Ayhan Date: Tue, 25 Oct 2022 16:23:30 +0200 Subject: [PATCH 2/2] Use variables_with_prefill_data and remove the extra parameters in vars --- .../ci/list_config_variables_service.rb | 2 +- lib/gitlab/ci/config.rb | 4 +++ lib/gitlab/ci/config/entry/variable.rb | 20 ++++++++--- lib/gitlab/ci/config/entry/variables.rb | 6 ++++ lib/gitlab/ci/variables/collection/item.rb | 5 +-- lib/gitlab/ci/yaml_processor/result.rb | 4 +-- .../gitlab/ci/config/entry/variable_spec.rb | 36 +++++++++++++++++++ .../gitlab/ci/config/entry/variables_spec.rb | 34 ++++++++++++++++++ .../ci/variables/collection/item_spec.rb | 6 ++-- spec/lib/gitlab/ci/yaml_processor_spec.rb | 14 +++++++- 10 files changed, 115 insertions(+), 16 deletions(-) diff --git a/app/services/ci/list_config_variables_service.rb b/app/services/ci/list_config_variables_service.rb index 5320c5be0e94eb..df4fbb9d362891 100644 --- a/app/services/ci/list_config_variables_service.rb +++ b/app/services/ci/list_config_variables_service.rb @@ -29,7 +29,7 @@ def calculate_reactive_cache(sha) user: current_user, sha: sha).execute - result.valid? ? result.root_variables_with_data : {} + result.valid? ? result.root_variables_with_prefill_data : {} end # Required for ReactiveCaching, it is also used in `reactive_cache_worker_finder` diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb index 661c6fb87e3077..ee537f4efe589d 100644 --- a/lib/gitlab/ci/config.rb +++ b/lib/gitlab/ci/config.rb @@ -73,6 +73,10 @@ def variables_with_data root.variables_entry.value_with_data end + def variables_with_prefill_data + root.variables_entry.value_with_prefill_data + end + def stages root.stages_value end diff --git a/lib/gitlab/ci/config/entry/variable.rb b/lib/gitlab/ci/config/entry/variable.rb index a606cd3f26fa30..16091758916e26 100644 --- a/lib/gitlab/ci/config/entry/variable.rb +++ b/lib/gitlab/ci/config/entry/variable.rb @@ -33,6 +33,10 @@ def value def value_with_data { value: @config.to_s } end + + def value_with_prefill_data + value_with_data + end end class ComplexVariable < ::Gitlab::Config::Entry::Node @@ -73,17 +77,21 @@ def value_with_data if ci_raw_variables_in_yaml_config_enabled? { value: value, - description: config_description, raw: (!config_expand if config_expand_defined?) }.compact else { - value: value, - description: config_description + value: value }.compact end end + def value_with_prefill_data + value_with_data.merge( + description: config_description + ).compact + end + def config_value @config[:value] end @@ -136,8 +144,10 @@ def value config_value.first end - def value_with_data - super.merge(value_options: config_value).compact + def value_with_prefill_data + super.merge( + value_options: config_value + ).compact end end diff --git a/lib/gitlab/ci/config/entry/variables.rb b/lib/gitlab/ci/config/entry/variables.rb index 4430a11dda73bd..ef4f74b9f56e0f 100644 --- a/lib/gitlab/ci/config/entry/variables.rb +++ b/lib/gitlab/ci/config/entry/variables.rb @@ -29,6 +29,12 @@ def value_with_data end end + def value_with_prefill_data + @entries.to_h do |key, entry| + [key.to_s, entry.value_with_prefill_data] + end + end + private def composable_class(_name, _config) diff --git a/lib/gitlab/ci/variables/collection/item.rb b/lib/gitlab/ci/variables/collection/item.rb index 6cd34170abe8ae..45faf4f63ebb66 100644 --- a/lib/gitlab/ci/variables/collection/item.rb +++ b/lib/gitlab/ci/variables/collection/item.rb @@ -10,10 +10,7 @@ class Item VARIABLES_REGEXP = /\$\$|%%|\$(?[a-zA-Z_][a-zA-Z0-9_]*)|\${\g?}|%\g%/.freeze.freeze VARIABLE_REF_CHARS = %w[$ %].freeze - # We accept additional parameters with `args` because `description` and `value_options` are sent - # from `Entry::Variable#value_with_data`. However, we ignore them because they are just used for - # the prefill-variables feature and not a real variable attribute. - def initialize(key:, value:, public: true, file: false, masked: false, raw: false, **args) + def initialize(key:, value:, public: true, file: false, masked: false, raw: false) raise ArgumentError, "`#{key}` must be of type String or nil value, while it was: #{value.class}" unless value.is_a?(String) || value.nil? diff --git a/lib/gitlab/ci/yaml_processor/result.rb b/lib/gitlab/ci/yaml_processor/result.rb index 37d3e8900e5c35..ff255543d3b2f2 100644 --- a/lib/gitlab/ci/yaml_processor/result.rb +++ b/lib/gitlab/ci/yaml_processor/result.rb @@ -7,7 +7,7 @@ module Ci class YamlProcessor class Result attr_reader :errors, :warnings, - :root_variables, :root_variables_with_data, + :root_variables, :root_variables_with_prefill_data, :stages, :jobs, :workflow_rules, :workflow_name @@ -70,7 +70,7 @@ def assign_valid_attributes transform_to_array(@ci_config.variables) end - @root_variables_with_data = @ci_config.variables_with_data + @root_variables_with_prefill_data = @ci_config.variables_with_prefill_data @stages = @ci_config.stages @jobs = @ci_config.normalized_jobs diff --git a/spec/lib/gitlab/ci/config/entry/variable_spec.rb b/spec/lib/gitlab/ci/config/entry/variable_spec.rb index 9afd3df350b6f8..d7023072312fc6 100644 --- a/spec/lib/gitlab/ci/config/entry/variable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/variable_spec.rb @@ -92,6 +92,12 @@ describe '#value_with_data' do subject(:value_with_data) { entry.value_with_data } + it { is_expected.to eq(value: 'value') } + end + + describe '#value_with_prefill_data' do + subject(:value_with_prefill_data) { entry.value_with_prefill_data } + it { is_expected.to eq(value: 'value', description: 'description') } end @@ -107,6 +113,12 @@ describe '#value_with_data' do subject(:value_with_data) { entry.value_with_data } + it { is_expected.to eq(value: 'value') } + end + + describe '#value_with_prefill_data' do + subject(:value_with_prefill_data) { entry.value_with_prefill_data } + it { is_expected.to eq(value: 'value', description: 'description') } end end @@ -123,6 +135,12 @@ describe '#value_with_data' do subject(:value_with_data) { entry.value_with_data } + it { is_expected.to eq(value: '123') } + end + + describe '#value_with_prefill_data' do + subject(:value_with_prefill_data) { entry.value_with_prefill_data } + it { is_expected.to eq(value: '123', description: 'description') } end end @@ -139,6 +157,12 @@ describe '#value_with_data' do subject(:value_with_data) { entry.value_with_data } + it { is_expected.to eq(value: 'value') } + end + + describe '#value_with_prefill_data' do + subject(:value_with_prefill_data) { entry.value_with_prefill_data } + it { is_expected.to eq(value: 'value', description: :description) } end end @@ -192,6 +216,12 @@ it { is_expected.to eq(value: 'value') } end + + describe '#value_with_prefill_data' do + subject(:value_with_prefill_data) { entry.value_with_prefill_data } + + it { is_expected.to eq(value: 'value') } + end end end @@ -311,6 +341,12 @@ describe '#value_with_data' do subject(:value_with_data) { entry.value_with_data } + it { is_expected.to eq(value: 'value') } + end + + describe '#value_with_prefill_data' do + subject(:value_with_prefill_data) { entry.value_with_prefill_data } + it { is_expected.to eq(value: 'value', description: 'description', value_options: %w[value value2]) } end end diff --git a/spec/lib/gitlab/ci/config/entry/variables_spec.rb b/spec/lib/gitlab/ci/config/entry/variables_spec.rb index 085f304094e4f1..609e4422d5c182 100644 --- a/spec/lib/gitlab/ci/config/entry/variables_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/variables_spec.rb @@ -66,6 +66,15 @@ ) end end + + describe '#value_with_prefill_data' do + it 'returns variable with prefill data' do + expect(entry.value_with_prefill_data).to eq( + 'VARIABLE_1' => { value: 'value 1' }, + 'VARIABLE_2' => { value: 'value 2' } + ) + end + end end context 'with numeric keys and values in the config' do @@ -119,6 +128,14 @@ describe '#value_with_data' do it 'returns variable with data' do expect(entry.value_with_data).to eq( + 'VARIABLE_1' => { value: 'value' } + ) + end + end + + describe '#value_with_prefill_data' do + it 'returns variable with prefill data' do + expect(entry.value_with_prefill_data).to eq( 'VARIABLE_1' => { value: 'value', description: 'variable 1' } ) end @@ -147,6 +164,14 @@ describe '#value_with_data' do it 'returns variable with data' do expect(entry.value_with_data).to eq( + 'VARIABLE_1' => { value: 'value1' } + ) + end + end + + describe '#value_with_prefill_data' do + it 'returns variable with prefill data' do + expect(entry.value_with_prefill_data).to eq( 'VARIABLE_1' => { value: 'value1', value_options: %w[value1 value2], description: 'variable 1' } ) end @@ -174,6 +199,15 @@ describe '#value_with_data' do it 'returns variable with data' do expect(entry.value_with_data).to eq( + 'VARIABLE_1' => { value: 'value 1' }, + 'VARIABLE_2' => { value: 'value 2' } + ) + end + end + + describe '#value_with_prefill_data' do + it 'returns variable with prefill data' do + expect(entry.value_with_prefill_data).to eq( 'VARIABLE_1' => { value: 'value 1', description: 'variable 1' }, 'VARIABLE_2' => { value: 'value 2' } ) diff --git a/spec/lib/gitlab/ci/variables/collection/item_spec.rb b/spec/lib/gitlab/ci/variables/collection/item_spec.rb index 87f9424ec53c21..9443bf6d6d5765 100644 --- a/spec/lib/gitlab/ci/variables/collection/item_spec.rb +++ b/spec/lib/gitlab/ci/variables/collection/item_spec.rb @@ -13,9 +13,9 @@ describe '.new' do context 'when unknown keyword is specified' do - it 'ignores the parameter' do - expect { described_class.new(key: variable_key, value: 'abc', description: 'hello') } - .not_to raise_error + it 'raises error' do + expect { described_class.new(key: variable_key, value: 'abc', files: true) } + .to raise_error ArgumentError, 'unknown keyword: :files' end end diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index dabe6e26f63376..28318a776f93e5 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -1229,9 +1229,15 @@ module Ci expect(execute.root_variables).to contain_exactly( { key: 'VAR1', value: 'value1' }, - { key: 'VAR2', value: 'value2', description: 'description2' }, + { key: 'VAR2', value: 'value2' }, { key: 'VAR3', value: 'value3', raw: true } ) + + expect(execute.root_variables_with_prefill_data).to eq( + 'VAR1' => { value: 'value1' }, + 'VAR2' => { value: 'value2', description: 'description2' }, + 'VAR3' => { value: 'value3', raw: true } + ) end context 'when the FF ci_raw_variables_in_yaml_config is disabled' do @@ -1251,6 +1257,12 @@ module Ci { key: 'VAR2', value: 'value2' }, { key: 'VAR3', value: 'value3' } ) + + expect(execute.root_variables_with_prefill_data).to eq( + 'VAR1' => { value: 'value1' }, + 'VAR2' => { value: 'value2', description: 'description2' }, + 'VAR3' => { value: 'value3' } + ) end end end -- GitLab