diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/lib/gitlab/ci/build/rules_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/ci/build/rules_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/build/rules_spec.rb | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/spec/lib/gitlab/ci/build/rules_spec.rb b/spec/lib/gitlab/ci/build/rules_spec.rb index cbeae33fbcf..a1af5b75f87 100644 --- a/spec/lib/gitlab/ci/build/rules_spec.rb +++ b/spec/lib/gitlab/ci/build/rules_spec.rb @@ -104,7 +104,7 @@ RSpec.describe Gitlab::Ci::Build::Rules do context 'with one rule without any clauses' do let(:rule_list) { [{ when: 'manual', allow_failure: true }] } - it { is_expected.to eq(described_class::Result.new('manual', nil, true)) } + it { is_expected.to eq(described_class::Result.new('manual', nil, true, nil)) } end context 'with one matching rule' do @@ -171,7 +171,7 @@ RSpec.describe Gitlab::Ci::Build::Rules do context 'with matching rule' do let(:rule_list) { [{ if: '$VAR == null', allow_failure: true }] } - it { is_expected.to eq(described_class::Result.new('on_success', nil, true)) } + it { is_expected.to eq(described_class::Result.new('on_success', nil, true, nil)) } end context 'with non-matching rule' do @@ -180,18 +180,60 @@ RSpec.describe Gitlab::Ci::Build::Rules do it { is_expected.to eq(described_class::Result.new('never')) } end end + + context 'with variables' do + context 'with matching rule' do + let(:rule_list) { [{ if: '$VAR == null', variables: { MY_VAR: 'my var' } }] } + + it { is_expected.to eq(described_class::Result.new('on_success', nil, nil, { MY_VAR: 'my var' })) } + end + end end describe 'Gitlab::Ci::Build::Rules::Result' do let(:when_value) { 'on_success' } let(:start_in) { nil } let(:allow_failure) { nil } + let(:variables) { nil } - subject { Gitlab::Ci::Build::Rules::Result.new(when_value, start_in, allow_failure) } + subject(:result) do + Gitlab::Ci::Build::Rules::Result.new(when_value, start_in, allow_failure, variables) + end describe '#build_attributes' do + let(:seed_attributes) { {} } + + subject(:build_attributes) do + result.build_attributes(seed_attributes) + end + it 'compacts nil values' do - expect(subject.build_attributes).to eq(options: {}, when: 'on_success') + is_expected.to eq(options: {}, when: 'on_success') + end + + context 'when there are variables in rules' do + let(:variables) { { VAR1: 'new var 1', VAR3: 'var 3' } } + + context 'when there are seed variables' do + let(:seed_attributes) do + { yaml_variables: [{ key: 'VAR1', value: 'var 1', public: true }, + { key: 'VAR2', value: 'var 2', public: true }] } + end + + it 'returns yaml_variables with override' do + is_expected.to include( + yaml_variables: [{ key: 'VAR1', value: 'new var 1', public: true }, + { key: 'VAR2', value: 'var 2', public: true }, + { key: 'VAR3', value: 'var 3', public: true }] + ) + end + end + + context 'when there is not seed variables' do + it 'does not return yaml_variables' do + is_expected.not_to have_key(:yaml_variables) + end + end end end @@ -200,7 +242,7 @@ RSpec.describe Gitlab::Ci::Build::Rules do let!(:when_value) { 'never' } it 'returns false' do - expect(subject.pass?).to eq(false) + expect(result.pass?).to eq(false) end end @@ -208,7 +250,7 @@ RSpec.describe Gitlab::Ci::Build::Rules do let!(:when_value) { 'on_success' } it 'returns true' do - expect(subject.pass?).to eq(true) + expect(result.pass?).to eq(true) end end end |