diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 15:13:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 15:13:06 +0300 |
commit | c7b2529418eb0fb802637709eafe8016a4d106b0 (patch) | |
tree | 858333642b5a371009f4e4eabcd5c0e2dd5df25f /spec/lib/gitlab/ci/variables | |
parent | 31522c5182bf14886900131c12d17d004ce28534 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/ci/variables')
-rw-r--r-- | spec/lib/gitlab/ci/variables/helpers_spec.rb | 123 |
1 files changed, 62 insertions, 61 deletions
diff --git a/spec/lib/gitlab/ci/variables/helpers_spec.rb b/spec/lib/gitlab/ci/variables/helpers_spec.rb index 2a1cdaeb3a7..fc1055751bd 100644 --- a/spec/lib/gitlab/ci/variables/helpers_spec.rb +++ b/spec/lib/gitlab/ci/variables/helpers_spec.rb @@ -15,27 +15,21 @@ RSpec.describe Gitlab::Ci::Variables::Helpers do end let(:result) do - [{ key: 'key1', value: 'value1' }, - { key: 'key2', value: 'value22' }, - { key: 'key3', value: 'value3' }] + [{ key: 'key1', value: 'value1', public: true }, + { key: 'key2', value: 'value22', public: true }, + { key: 'key3', value: 'value3', public: true }] end subject { described_class.merge_variables(current_variables, new_variables) } - it { is_expected.to match_array(result) } + it { is_expected.to eq(result) } context 'when new variables is a hash' do let(:new_variables) do { 'key2' => 'value22', 'key3' => 'value3' } end - let(:result) do - [{ key: 'key1', value: 'value1' }, - { key: 'key2', value: 'value22' }, - { key: 'key3', value: 'value3' }] - end - - it { is_expected.to match_array(result) } + it { is_expected.to eq(result) } end context 'when new variables is a hash with symbol keys' do @@ -43,72 +37,79 @@ RSpec.describe Gitlab::Ci::Variables::Helpers do { key2: 'value22', key3: 'value3' } end - let(:result) do - [{ key: 'key1', value: 'value1' }, - { key: 'key2', value: 'value22' }, - { key: 'key3', value: 'value3' }] - end - - it { is_expected.to match_array(result) } + it { is_expected.to eq(result) } end context 'when new variables is nil' do let(:new_variables) {} let(:result) do - [{ key: 'key1', value: 'value1' }, - { key: 'key2', value: 'value2' }] + [{ key: 'key1', value: 'value1', public: true }, + { key: 'key2', value: 'value2', public: true }] end - it { is_expected.to match_array(result) } + it { is_expected.to eq(result) } end end - describe '.transform_to_array' do - subject { described_class.transform_to_array(variables) } + describe '.transform_to_yaml_variables' do + let(:variables) do + { 'key1' => 'value1', 'key2' => 'value2' } + end - context 'when values are strings' do - let(:variables) do - { 'key1' => 'value1', 'key2' => 'value2' } - end + let(:result) do + [{ key: 'key1', value: 'value1', public: true }, + { key: 'key2', value: 'value2', public: true }] + end - let(:result) do - [{ key: 'key1', value: 'value1' }, - { key: 'key2', value: 'value2' }] - end + subject { described_class.transform_to_yaml_variables(variables) } + + it { is_expected.to eq(result) } + + context 'when variables is nil' do + let(:variables) {} - it { is_expected.to match_array(result) } + 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 }] end + let(:result) do + { 'key1' => 'value1', 'key2' => 'value2' } + end + + subject { described_class.transform_from_yaml_variables(variables) } + + it { is_expected.to eq(result) } + context 'when variables is nil' do let(:variables) {} - it { is_expected.to match_array([]) } + it { is_expected.to eq({}) } end - context 'when values are hashes' do + context 'when variables is a hash' do let(:variables) do - { 'key1' => { value: 'value1', description: 'var 1' }, 'key2' => { value: 'value2' } } - end - - let(:result) do - [{ key: 'key1', value: 'value1', description: 'var 1' }, - { key: 'key2', value: 'value2' }] + { key1: 'value1', 'key2' => 'value2' } end - it { is_expected.to match_array(result) } - - 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(result) } + end - let(:result) do - [{ key: 'key1', value: 'value1' }, - { key: 'key2', value: 'value2' }] - end + context 'when variables contain integers and symbols' do + let(:variables) do + { key1: 1, key2: :value2 } + end - it { is_expected.to match_array(result) } + let(:result1) do + { 'key1' => '1', 'key2' => 'value2' } end + + it { is_expected.to eq(result1) } end end @@ -126,35 +127,35 @@ RSpec.describe Gitlab::Ci::Variables::Helpers do let(:inheritance) { true } let(:result) do - [{ key: 'key1', value: 'value1' }, - { key: 'key2', value: 'value22' }, - { key: 'key3', value: 'value3' }] + [{ key: 'key1', value: 'value1', public: true }, + { key: 'key2', value: 'value22', public: true }, + { key: 'key3', value: 'value3', public: true }] end subject { described_class.inherit_yaml_variables(from: from, to: to, inheritance: inheritance) } - it { is_expected.to match_array(result) } + it { is_expected.to eq(result) } context 'when inheritance is false' do let(:inheritance) { false } let(:result) do - [{ key: 'key2', value: 'value22' }, - { key: 'key3', value: 'value3' }] + [{ key: 'key2', value: 'value22', public: true }, + { key: 'key3', value: 'value3', public: true }] end - it { is_expected.to match_array(result) } + it { is_expected.to eq(result) } end context 'when inheritance is array' do let(:inheritance) { ['key2'] } let(:result) do - [{ key: 'key2', value: 'value22' }, - { key: 'key3', value: 'value3' }] + [{ key: 'key2', value: 'value22', public: true }, + { key: 'key3', value: 'value3', public: true }] end - it { is_expected.to match_array(result) } + it { is_expected.to eq(result) } end end end |