summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/build/rules/rule/clause
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/build/rules/rule/clause')
-rw-r--r--spec/lib/gitlab/ci/build/rules/rule/clause/changes_spec.rb17
-rw-r--r--spec/lib/gitlab/ci/build/rules/rule/clause/exists_spec.rb27
2 files changed, 44 insertions, 0 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
new file mode 100644
index 00000000000..076de3646b0
--- /dev/null
+++ b/spec/lib/gitlab/ci/build/rules/rule/clause/changes_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
+ describe '#satisfied_by?' do
+ it_behaves_like 'a glob matching rule' do
+ let(:pipeline) { build(:ci_pipeline) }
+
+ before do
+ allow(pipeline).to receive(:modified_paths).and_return(files.keys)
+ end
+
+ subject { described_class.new(globs).satisfied_by?(pipeline, nil) }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/ci/build/rules/rule/clause/exists_spec.rb b/spec/lib/gitlab/ci/build/rules/rule/clause/exists_spec.rb
new file mode 100644
index 00000000000..3605bac7dfc
--- /dev/null
+++ b/spec/lib/gitlab/ci/build/rules/rule/clause/exists_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Ci::Build::Rules::Rule::Clause::Exists do
+ describe '#satisfied_by?' do
+ let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.head_commit.sha) }
+
+ subject { described_class.new(globs).satisfied_by?(pipeline, nil) }
+
+ it_behaves_like 'a glob matching rule' do
+ let(:project) { create(:project, :custom_repo, files: files) }
+ end
+
+ context 'after pattern comparision limit is reached' do
+ let(:globs) { ['*definitely_not_a_matching_glob*'] }
+ let(:project) { create(:project, :repository) }
+
+ before do
+ stub_const('Gitlab::Ci::Build::Rules::Rule::Clause::Exists::MAX_PATTERN_COMPARISONS', 2)
+ expect(File).to receive(:fnmatch?).exactly(2).times.and_call_original
+ end
+
+ it { is_expected.to be_truthy }
+ end
+ end
+end