diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/lib/gitlab/ci/variables | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/lib/gitlab/ci/variables')
-rw-r--r-- | spec/lib/gitlab/ci/variables/builder_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/variables/collection_spec.rb | 32 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/variables/helpers_spec.rb | 113 |
3 files changed, 84 insertions, 64 deletions
diff --git a/spec/lib/gitlab/ci/variables/builder_spec.rb b/spec/lib/gitlab/ci/variables/builder_spec.rb index 8ec0846bdca..6ab2089cce8 100644 --- a/spec/lib/gitlab/ci/variables/builder_spec.rb +++ b/spec/lib/gitlab/ci/variables/builder_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::Ci::Variables::Builder do + include Ci::TemplateHelpers let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, :repository, namespace: group) } let_it_be_with_reload(:pipeline) { create(:ci_pipeline, project: project) } @@ -92,6 +93,8 @@ RSpec.describe Gitlab::Ci::Variables::Builder do value: project.pages_url }, { key: 'CI_API_V4_URL', value: API::Helpers::Version.new('v4').root_url }, + { key: 'CI_TEMPLATE_REGISTRY_HOST', + value: template_registry_host }, { key: 'CI_PIPELINE_IID', value: pipeline.iid.to_s }, { key: 'CI_PIPELINE_SOURCE', diff --git a/spec/lib/gitlab/ci/variables/collection_spec.rb b/spec/lib/gitlab/ci/variables/collection_spec.rb index 26c560565e0..8ac03301322 100644 --- a/spec/lib/gitlab/ci/variables/collection_spec.rb +++ b/spec/lib/gitlab/ci/variables/collection_spec.rb @@ -302,6 +302,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection do .append(key: 'CI_BUILD_ID', value: '1') .append(key: 'RAW_VAR', value: '$TEST1', raw: true) .append(key: 'TEST1', value: 'test-3') + .append(key: 'FILEVAR1', value: 'file value 1', file: true) end context 'table tests' do @@ -311,28 +312,23 @@ RSpec.describe Gitlab::Ci::Variables::Collection do { "empty value": { value: '', - result: '', - keep_undefined: false + result: '' }, "simple expansions": { value: 'key$TEST1-$CI_BUILD_ID', - result: 'keytest-3-1', - keep_undefined: false + result: 'keytest-3-1' }, "complex expansion": { value: 'key${TEST1}-${CI_JOB_NAME}', - result: 'keytest-3-test-1', - keep_undefined: false + result: 'keytest-3-test-1' }, "complex expansions with raw variable": { value: 'key${RAW_VAR}-${CI_JOB_NAME}', - result: 'key$TEST1-test-1', - keep_undefined: false + result: 'key$TEST1-test-1' }, "missing variable not keeping original": { value: 'key${MISSING_VAR}-${CI_JOB_NAME}', - result: 'key-test-1', - keep_undefined: false + result: 'key-test-1' }, "missing variable keeping original": { value: 'key${MISSING_VAR}-${CI_JOB_NAME}', @@ -341,14 +337,24 @@ RSpec.describe Gitlab::Ci::Variables::Collection do }, "escaped characters are kept intact": { value: 'key-$TEST1-%%HOME%%-$${HOME}', - result: 'key-test-3-%%HOME%%-$${HOME}', - keep_undefined: false + result: 'key-test-3-%%HOME%%-$${HOME}' + }, + "file variable with expand_file_vars: true": { + value: 'key-$FILEVAR1-$TEST1', + result: 'key-file value 1-test-3' + }, + "file variable with expand_file_vars: false": { + value: 'key-$FILEVAR1-$TEST1', + result: 'key-$FILEVAR1-test-3', + expand_file_vars: false } } end with_them do - subject { collection.expand_value(value, keep_undefined: keep_undefined) } + let(:options) { { keep_undefined: keep_undefined, expand_file_vars: expand_file_vars }.compact } + + subject(:result) { collection.expand_value(value, **options) } it 'matches expected expansion' do is_expected.to eq(result) diff --git a/spec/lib/gitlab/ci/variables/helpers_spec.rb b/spec/lib/gitlab/ci/variables/helpers_spec.rb index f13b334c10e..2a1cdaeb3a7 100644 --- a/spec/lib/gitlab/ci/variables/helpers_spec.rb +++ b/spec/lib/gitlab/ci/variables/helpers_spec.rb @@ -15,21 +15,27 @@ RSpec.describe Gitlab::Ci::Variables::Helpers do end let(:result) do - [{ key: 'key1', value: 'value1', public: true }, - { key: 'key2', value: 'value22', public: true }, - { key: 'key3', value: 'value3', public: true }] + [{ key: 'key1', value: 'value1' }, + { key: 'key2', value: 'value22' }, + { key: 'key3', value: 'value3' }] end subject { described_class.merge_variables(current_variables, new_variables) } - it { is_expected.to eq(result) } + it { is_expected.to match_array(result) } context 'when new variables is a hash' do let(:new_variables) do { 'key2' => 'value22', 'key3' => 'value3' } end - it { is_expected.to eq(result) } + let(:result) do + [{ key: 'key1', value: 'value1' }, + { key: 'key2', value: 'value22' }, + { key: 'key3', value: 'value3' }] + end + + it { is_expected.to match_array(result) } end context 'when new variables is a hash with symbol keys' do @@ -37,67 +43,72 @@ RSpec.describe Gitlab::Ci::Variables::Helpers do { key2: 'value22', key3: 'value3' } end - it { is_expected.to eq(result) } + let(:result) do + [{ key: 'key1', value: 'value1' }, + { key: 'key2', value: 'value22' }, + { key: 'key3', value: 'value3' }] + end + + it { is_expected.to match_array(result) } end context 'when new variables is nil' do let(:new_variables) {} let(:result) do - [{ key: 'key1', value: 'value1', public: true }, - { key: 'key2', value: 'value2', public: true }] + [{ key: 'key1', value: 'value1' }, + { key: 'key2', value: 'value2' }] end - it { is_expected.to eq(result) } + it { is_expected.to match_array(result) } end end - describe '.transform_to_yaml_variables' do - let(:variables) do - { 'key1' => 'value1', 'key2' => 'value2' } - end + describe '.transform_to_array' do + subject { described_class.transform_to_array(variables) } - let(:result) do - [{ key: 'key1', value: 'value1', public: true }, - { key: 'key2', value: 'value2', public: true }] - end + context 'when values are strings' do + let(:variables) do + { 'key1' => 'value1', 'key2' => 'value2' } + end - subject { described_class.transform_to_yaml_variables(variables) } + let(:result) do + [{ key: 'key1', value: 'value1' }, + { key: 'key2', value: 'value2' }] + end - it { is_expected.to eq(result) } + it { is_expected.to match_array(result) } + end context 'when variables is nil' do let(:variables) {} - it { is_expected.to eq([]) } - end - end - - describe '.transform_from_yaml_variables' do - let(:variables) do - [{ key: 'key1', value: 'value1', public: true }, - { key: 'key2', value: 'value2', public: true }] + it { is_expected.to match_array([]) } end - let(:result) do - { 'key1' => 'value1', 'key2' => 'value2' } - end + context 'when values are hashes' do + let(:variables) do + { 'key1' => { value: 'value1', description: 'var 1' }, 'key2' => { value: 'value2' } } + end - subject { described_class.transform_from_yaml_variables(variables) } + let(:result) do + [{ key: 'key1', value: 'value1', description: 'var 1' }, + { key: 'key2', value: 'value2' }] + end - it { is_expected.to eq(result) } + it { is_expected.to match_array(result) } - context 'when variables is nil' do - let(:variables) {} + context 'when a value data has `key` as a key' do + let(:variables) do + { 'key1' => { value: 'value1', key: 'new_key1' }, 'key2' => { value: 'value2' } } + end - it { is_expected.to eq({}) } - end + let(:result) do + [{ key: 'key1', value: 'value1' }, + { key: 'key2', value: 'value2' }] + end - context 'when variables is a hash' do - let(:variables) do - { key1: 'value1', 'key2' => 'value2' } + it { is_expected.to match_array(result) } end - - it { is_expected.to eq(result) } end end @@ -115,35 +126,35 @@ RSpec.describe Gitlab::Ci::Variables::Helpers do let(:inheritance) { true } let(:result) do - [{ key: 'key1', value: 'value1', public: true }, - { key: 'key2', value: 'value22', public: true }, - { key: 'key3', value: 'value3', public: true }] + [{ key: 'key1', value: 'value1' }, + { key: 'key2', value: 'value22' }, + { key: 'key3', value: 'value3' }] end subject { described_class.inherit_yaml_variables(from: from, to: to, inheritance: inheritance) } - it { is_expected.to eq(result) } + it { is_expected.to match_array(result) } context 'when inheritance is false' do let(:inheritance) { false } let(:result) do - [{ key: 'key2', value: 'value22', public: true }, - { key: 'key3', value: 'value3', public: true }] + [{ key: 'key2', value: 'value22' }, + { key: 'key3', value: 'value3' }] end - it { is_expected.to eq(result) } + it { is_expected.to match_array(result) } end context 'when inheritance is array' do let(:inheritance) { ['key2'] } let(:result) do - [{ key: 'key2', value: 'value22', public: true }, - { key: 'key3', value: 'value3', public: true }] + [{ key: 'key2', value: 'value22' }, + { key: 'key3', value: 'value3' }] end - it { is_expected.to eq(result) } + it { is_expected.to match_array(result) } end end end |