Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/build/rules/rule/clause/changes_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/build/rules/rule/clause/changes_spec.rb98
1 files changed, 95 insertions, 3 deletions
diff --git a/spec/lib/gitlab/ci/build/rules/rule/clause/changes_spec.rb b/spec/lib/gitlab/ci/build/rules/rule/clause/changes_spec.rb
index 3892b88598a..234ba68d627 100644
--- a/spec/lib/gitlab/ci/build/rules/rule/clause/changes_spec.rb
+++ b/spec/lib/gitlab/ci/build/rules/rule/clause/changes_spec.rb
@@ -4,7 +4,9 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
describe '#satisfied_by?' do
- subject { described_class.new(globs).satisfied_by?(pipeline, context) }
+ let(:context) { instance_double(Gitlab::Ci::Build::Context::Base) }
+
+ subject(:satisfied_by) { described_class.new(globs).satisfied_by?(pipeline, context) }
context 'a glob matching rule' do
using RSpec::Parameterized::TableSyntax
@@ -18,11 +20,9 @@ RSpec.describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
# rubocop:disable Layout/LineLength
where(:case_name, :globs, :files, :satisfied) do
- 'exact top-level match' | ['Dockerfile'] | { 'Dockerfile' => '', 'Gemfile' => '' } | true
'exact top-level match' | { paths: ['Dockerfile'] } | { 'Dockerfile' => '', 'Gemfile' => '' } | true
'exact top-level no match' | { paths: ['Dockerfile'] } | { 'Gemfile' => '' } | false
'pattern top-level match' | { paths: ['Docker*'] } | { 'Dockerfile' => '', 'Gemfile' => '' } | true
- 'pattern top-level no match' | ['Docker*'] | { 'Gemfile' => '' } | false
'pattern top-level no match' | { paths: ['Docker*'] } | { 'Gemfile' => '' } | false
'exact nested match' | { paths: ['project/build.properties'] } | { 'project/build.properties' => '' } | true
'exact nested no match' | { paths: ['project/build.properties'] } | { 'project/README.md' => '' } | false
@@ -92,5 +92,97 @@ RSpec.describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
it { is_expected.to be_truthy }
end
end
+
+ context 'when using compare_to' do
+ let_it_be(:project) do
+ create(:project, :custom_repo,
+ files: { 'README.md' => 'readme' })
+ end
+
+ let_it_be(:user) { project.owner }
+
+ before_all do
+ project.repository.add_branch(user, 'feature_1', 'master')
+
+ project.repository.create_file(
+ user, 'file1.txt', 'file 1', message: 'Create file1.txt', branch_name: 'feature_1'
+ )
+ project.repository.add_tag(user, 'tag_1', 'feature_1')
+
+ project.repository.create_file(
+ user, 'file2.txt', 'file 2', message: 'Create file2.txt', branch_name: 'feature_1'
+ )
+ project.repository.add_branch(user, 'feature_2', 'feature_1')
+
+ project.repository.update_file(
+ user, 'file2.txt', 'file 2 updated', message: 'Update file2.txt', branch_name: 'feature_2'
+ )
+ end
+
+ context 'when compare_to is branch or tag' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:pipeline_ref, :compare_to, :paths, :ff, :result) do
+ 'feature_1' | 'master' | ['file1.txt'] | true | true
+ 'feature_1' | 'master' | ['README.md'] | true | false
+ 'feature_1' | 'master' | ['xyz.md'] | true | false
+ 'feature_2' | 'master' | ['file1.txt'] | true | true
+ 'feature_2' | 'master' | ['file2.txt'] | true | true
+ 'feature_2' | 'feature_1' | ['file1.txt'] | true | false
+ 'feature_2' | 'feature_1' | ['file1.txt'] | false | true
+ 'feature_2' | 'feature_1' | ['file2.txt'] | true | true
+ 'feature_1' | 'tag_1' | ['file1.txt'] | true | false
+ 'feature_1' | 'tag_1' | ['file1.txt'] | false | true
+ 'feature_1' | 'tag_1' | ['file2.txt'] | true | true
+ 'feature_2' | 'tag_1' | ['file2.txt'] | true | true
+ end
+
+ with_them do
+ let(:globs) { { paths: paths, compare_to: compare_to } }
+
+ let(:pipeline) do
+ build(:ci_pipeline, project: project, ref: pipeline_ref, sha: project.commit(pipeline_ref).sha)
+ end
+
+ before do
+ stub_feature_flags(ci_rules_changes_compare: ff)
+ end
+
+ it { is_expected.to eq(result) }
+ end
+ end
+
+ context 'when compare_to is a sha' do
+ let(:globs) { { paths: ['file2.txt'], compare_to: project.commit('tag_1').sha } }
+
+ let(:pipeline) do
+ build(:ci_pipeline, project: project, ref: 'feature_2', sha: project.commit('feature_2').sha)
+ end
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'when compare_to is not a valid ref' do
+ let(:globs) { { paths: ['file1.txt'], compare_to: 'xyz' } }
+
+ let(:pipeline) do
+ build(:ci_pipeline, project: project, ref: 'feature_2', sha: project.commit('feature_2').sha)
+ end
+
+ it 'raises ParseError' do
+ expect { satisfied_by }.to raise_error(
+ ::Gitlab::Ci::Build::Rules::Rule::Clause::ParseError, 'rules:changes:compare_to is not a valid ref'
+ )
+ end
+
+ context 'when the FF ci_rules_changes_compare is disabled' do
+ before do
+ stub_feature_flags(ci_rules_changes_compare: false)
+ end
+
+ it { is_expected.to be_truthy }
+ end
+ end
+ end
end
end