diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-25 15:12:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-25 15:12:20 +0300 |
commit | 73507eaf1a77c5c05ae17c9f7ac29bbeb8bf5be1 (patch) | |
tree | 7f9b8b4246b9d0ce354866b07f4e9f657ac9665d /spec/lib | |
parent | 86ace8a66caeb11a2912e15e8a9abc3d9e4960c2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/ci/build/rules/rule/clause/exists_spec.rb | 46 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/external/file/remote_spec.rb | 39 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/external/processor_spec.rb | 30 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/utils/delegator_override_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/utils/nokogiri_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/utils/sanitize_node_link_spec.rb | 4 |
7 files changed, 103 insertions, 22 deletions
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 index f192862c1c4..f9ebab149a5 100644 --- a/spec/lib/gitlab/ci/build/rules/rule/clause/exists_spec.rb +++ b/spec/lib/gitlab/ci/build/rules/rule/clause/exists_spec.rb @@ -3,44 +3,54 @@ require 'spec_helper' RSpec.describe Gitlab::Ci::Build::Rules::Rule::Clause::Exists do - shared_examples 'an exists rule with a context' do - subject { described_class.new(globs).satisfied_by?(pipeline, context) } + describe '#satisfied_by?' do + shared_examples 'an exists rule with a context' do + it_behaves_like 'a glob matching rule' do + let(:project) { create(:project, :custom_repo, files: files) } + end - 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) } - 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?).twice.and_call_original + end - before do - stub_const('Gitlab::Ci::Build::Rules::Rule::Clause::Exists::MAX_PATTERN_COMPARISONS', 2) - expect(File).to receive(:fnmatch?).twice.and_call_original + it { is_expected.to be_truthy } end - - it { is_expected.to be_truthy } end - end - describe '#satisfied_by?' do - let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.head_commit.sha) } + subject(:satisfied_by?) { described_class.new(globs).satisfied_by?(nil, context) } context 'when context is Build::Context::Build' do it_behaves_like 'an exists rule with a context' do - let(:context) { Gitlab::Ci::Build::Context::Build.new(pipeline, sha: 'abc1234') } + let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.commit.sha) } + let(:context) { Gitlab::Ci::Build::Context::Build.new(pipeline, sha: project.repository.commit.sha) } end end context 'when context is Build::Context::Global' do it_behaves_like 'an exists rule with a context' do + let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.commit.sha) } let(:context) { Gitlab::Ci::Build::Context::Global.new(pipeline, yaml_variables: {}) } end end context 'when context is Config::External::Context' do + let(:context) { Gitlab::Ci::Config::External::Context.new(project: project, sha: sha) } + it_behaves_like 'an exists rule with a context' do - let(:context) { Gitlab::Ci::Config::External::Context.new(project: project, sha: project.repository.tree.sha) } + let(:sha) { project.repository.commit.sha } + end + + context 'when context has no project' do + let(:globs) { ['Dockerfile'] } + let(:project) {} + let(:sha) { 'abc1234' } + + it { is_expected.to eq(false) } end end end diff --git a/spec/lib/gitlab/ci/config/external/file/remote_spec.rb b/spec/lib/gitlab/ci/config/external/file/remote_spec.rb index 45dfea636f3..c22afb32756 100644 --- a/spec/lib/gitlab/ci/config/external/file/remote_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/remote_spec.rb @@ -219,4 +219,43 @@ RSpec.describe Gitlab::Ci::Config::External::File::Remote do ) } end + + describe '#to_hash' do + subject(:to_hash) { remote_file.to_hash } + + before do + stub_full_request(location).to_return(body: remote_file_content) + end + + context 'with a valid remote file' do + it 'returns the content as a hash' do + expect(to_hash).to eql( + before_script: ["apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs", + "ruby -v", + "which ruby", + "bundle install --jobs $(nproc) \"${FLAGS[@]}\""] + ) + end + end + + context 'when it has `include` with rules:exists' do + let(:remote_file_content) do + <<~HEREDOC + include: + - local: another-file.yml + rules: + - exists: [Dockerfile] + HEREDOC + end + + it 'returns the content as a hash' do + expect(to_hash).to eql( + include: [ + { local: 'another-file.yml', + rules: [{ exists: ['Dockerfile'] }] } + ] + ) + end + end + end end diff --git a/spec/lib/gitlab/ci/config/external/processor_spec.rb b/spec/lib/gitlab/ci/config/external/processor_spec.rb index 841a46e197d..b1dff6f9723 100644 --- a/spec/lib/gitlab/ci/config/external/processor_spec.rb +++ b/spec/lib/gitlab/ci/config/external/processor_spec.rb @@ -94,6 +94,36 @@ RSpec.describe Gitlab::Ci::Config::External::Processor do end end + context 'when the remote file has `include` with rules:exists' do + let(:remote_file) { 'https://gitlab.com/gitlab-org/gitlab-foss/blob/1234/.gitlab-ci-1.yml' } + let(:values) { { include: remote_file, image: 'image:1.0' } } + let(:external_file_content) do + <<-HEREDOC + include: + - local: another-file.yml + rules: + - exists: [Dockerfile] + + rspec: + script: + - bundle exec rspec + HEREDOC + end + + before do + stub_full_request(remote_file).to_return(body: external_file_content) + end + + it 'evaluates the rule as false' do + output = processor.perform + expect(output.keys).to match_array([:image, :rspec]) + end + + it "removes the 'include' keyword" do + expect(processor.perform[:include]).to be_nil + end + end + context 'with a valid local external file is defined' do let(:values) { { include: '/lib/gitlab/ci/templates/template.yml', image: 'image:1.0' } } let(:local_file_content) do diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 9aec3271913..c0be5b01cef 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -654,11 +654,9 @@ search_data: merge_request_assignees: - merge_request - assignee -- updated_state_by merge_request_reviewers: - merge_request - reviewer -- updated_state_by lfs_file_locks: - user project_badges: diff --git a/spec/lib/gitlab/utils/delegator_override_spec.rb b/spec/lib/gitlab/utils/delegator_override_spec.rb index af4c7fa5d8e..2dafa75e344 100644 --- a/spec/lib/gitlab/utils/delegator_override_spec.rb +++ b/spec/lib/gitlab/utils/delegator_override_spec.rb @@ -31,6 +31,7 @@ RSpec.describe Gitlab::Utils::DelegatorOverride do before do stub_env('STATIC_VERIFICATION', 'true') + described_class.validators.clear end describe '.delegator_target' do diff --git a/spec/lib/gitlab/utils/nokogiri_spec.rb b/spec/lib/gitlab/utils/nokogiri_spec.rb index 90f137f53c8..7b4c63f9168 100644 --- a/spec/lib/gitlab/utils/nokogiri_spec.rb +++ b/spec/lib/gitlab/utils/nokogiri_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' +require 'rspec-parameterized' RSpec.describe Gitlab::Utils::Nokogiri do describe '#css_to_xpath' do diff --git a/spec/lib/gitlab/utils/sanitize_node_link_spec.rb b/spec/lib/gitlab/utils/sanitize_node_link_spec.rb index 3ab592dfc62..1fc10bc3aa8 100644 --- a/spec/lib/gitlab/utils/sanitize_node_link_spec.rb +++ b/spec/lib/gitlab/utils/sanitize_node_link_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' +require 'html/pipeline' +require 'addressable' RSpec.describe Gitlab::Utils::SanitizeNodeLink do let(:klass) do |