diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 07:33:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 07:33:21 +0000 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/lib/gitlab/ci/build | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) | |
download | gitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/lib/gitlab/ci/build')
-rw-r--r-- | spec/lib/gitlab/ci/build/rules/rule/clause/if_spec.rb | 74 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/build/rules_spec.rb | 13 |
2 files changed, 87 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/build/rules/rule/clause/if_spec.rb b/spec/lib/gitlab/ci/build/rules/rule/clause/if_spec.rb new file mode 100644 index 00000000000..81bce989833 --- /dev/null +++ b/spec/lib/gitlab/ci/build/rules/rule/clause/if_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'support/helpers/stubbed_feature' +require 'support/helpers/stub_feature_flags' + +RSpec.describe Gitlab::Ci::Build::Rules::Rule::Clause::If do + include StubFeatureFlags + + subject(:if_clause) { described_class.new(expression) } + + describe '#satisfied_by?' do + let(:context_class) { Gitlab::Ci::Build::Context::Base } + let(:rules_context) { instance_double(context_class, variables_hash: {}) } + + subject(:satisfied_by?) { if_clause.satisfied_by?(nil, rules_context) } + + context 'when expression is a basic string comparison' do + context 'when comparison is true' do + let(:expression) { '"value" == "value"' } + + it { is_expected.to eq(true) } + end + + context 'when comparison is false' do + let(:expression) { '"value" == "other"' } + + it { is_expected.to eq(false) } + end + end + + context 'when expression is a regexp' do + context 'when comparison is true' do + let(:expression) { '"abcde" =~ /^ab.*/' } + + it { is_expected.to eq(true) } + end + + context 'when comparison is false' do + let(:expression) { '"abcde" =~ /^af.*/' } + + it { is_expected.to eq(false) } + end + + context 'when both side of the expression are variables' do + let(:expression) { '$teststring =~ $pattern' } + + context 'when comparison is true' do + let(:rules_context) do + instance_double(context_class, variables_hash: { 'teststring' => 'abcde', 'pattern' => '/^ab.*/' }) + end + + it { is_expected.to eq(true) } + + context 'when the FF ci_fix_rules_if_comparison_with_regexp_variable is disabled' do + before do + stub_feature_flags(ci_fix_rules_if_comparison_with_regexp_variable: false) + end + + it { is_expected.to eq(false) } + end + end + + context 'when comparison is false' do + let(:rules_context) do + instance_double(context_class, variables_hash: { 'teststring' => 'abcde', 'pattern' => '/^af.*/' }) + end + + it { is_expected.to eq(false) } + end + end + end + end +end diff --git a/spec/lib/gitlab/ci/build/rules_spec.rb b/spec/lib/gitlab/ci/build/rules_spec.rb index 37bfdca4d1d..e82dcd0254d 100644 --- a/spec/lib/gitlab/ci/build/rules_spec.rb +++ b/spec/lib/gitlab/ci/build/rules_spec.rb @@ -188,6 +188,19 @@ RSpec.describe Gitlab::Ci::Build::Rules do it { is_expected.to eq(described_class::Result.new('on_success', nil, nil, { MY_VAR: 'my var' })) } end end + + context 'with a regexp variable matching rule' do + let(:rule_list) { [{ if: '"abcde" =~ $pattern' }] } + + before do + allow(ci_build).to receive(:scoped_variables).and_return( + Gitlab::Ci::Variables::Collection.new + .append(key: 'pattern', value: '/^ab.*/', public: true) + ) + end + + it { is_expected.to eq(described_class::Result.new('on_success')) } + end end describe 'Gitlab::Ci::Build::Rules::Result' do |