diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-15 18:09:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-15 18:09:29 +0300 |
commit | 16cdacff02fbf0069182e090df2eeaa754007957 (patch) | |
tree | 5d19a3022bb7266834dad55a757f53bd48dc44e5 /spec/lib | |
parent | 37439afe69efe58e2351d899d231670d945be5e2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
18 files changed, 472 insertions, 14 deletions
diff --git a/spec/lib/api/entities/plan_limit_spec.rb b/spec/lib/api/entities/plan_limit_spec.rb index a88ea3f4cad..baaaeb0b600 100644 --- a/spec/lib/api/entities/plan_limit_spec.rb +++ b/spec/lib/api/entities/plan_limit_spec.rb @@ -25,7 +25,8 @@ RSpec.describe API::Entities::PlanLimit do :nuget_max_file_size, :pypi_max_file_size, :terraform_module_max_file_size, - :storage_size_limit + :storage_size_limit, + :pipeline_hierarchy_size ) end diff --git a/spec/lib/banzai/filter/commit_trailers_filter_spec.rb b/spec/lib/banzai/filter/commit_trailers_filter_spec.rb index c22517621c1..3ebe0798972 100644 --- a/spec/lib/banzai/filter/commit_trailers_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_trailers_filter_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'ffaker' -RSpec.describe Banzai::Filter::CommitTrailersFilter do +RSpec.describe Banzai::Filter::CommitTrailersFilter, feature_category: :source_code_management do include FilterSpecHelper include CommitTrailersSpecHelper diff --git a/spec/lib/gitlab/ci/config/external/mapper/base_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/base_spec.rb new file mode 100644 index 00000000000..0fdcc5e8ff7 --- /dev/null +++ b/spec/lib/gitlab/ci/config/external/mapper/base_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Config::External::Mapper::Base, feature_category: :pipeline_authoring do + let(:test_class) do + Class.new(described_class) do + def self.name + 'TestClass' + end + end + end + + let(:context) { Gitlab::Ci::Config::External::Context.new } + let(:mapper) { test_class.new(context) } + + describe '#process' do + subject(:process) { mapper.process } + + context 'when the method is not implemented' do + it 'raises NotImplementedError' do + expect { process }.to raise_error(NotImplementedError) + end + end + + context 'when the method is implemented' do + before do + test_class.class_eval do + def process_without_instrumentation + 'test' + end + end + end + + it 'calls the method' do + expect(process).to eq('test') + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/external/mapper/filter_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/filter_spec.rb new file mode 100644 index 00000000000..df2a2f0fd01 --- /dev/null +++ b/spec/lib/gitlab/ci/config/external/mapper/filter_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Config::External::Mapper::Filter, feature_category: :pipeline_authoring do + let_it_be(:variables) do + Gitlab::Ci::Variables::Collection.new.tap do |variables| + variables.append(key: 'VARIABLE1', value: 'hello') + end + end + + let_it_be(:context) do + Gitlab::Ci::Config::External::Context.new(variables: variables) + end + + subject(:filter) { described_class.new(context) } + + describe '#process' do + let(:locations) do + [{ local: 'config/.gitlab-ci.yml', rules: [{ if: '$VARIABLE1' }] }, + { remote: 'https://example.com/.gitlab-ci.yml', rules: [{ if: '$VARIABLE2' }] }] + end + + subject(:process) { filter.process(locations) } + + it 'filters locations according to rules' do + is_expected.to eq( + [{ local: 'config/.gitlab-ci.yml', rules: [{ if: '$VARIABLE1' }] }] + ) + end + end +end diff --git a/spec/lib/gitlab/ci/config/external/mapper/location_expander_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/location_expander_spec.rb new file mode 100644 index 00000000000..b14b6b0ca29 --- /dev/null +++ b/spec/lib/gitlab/ci/config/external/mapper/location_expander_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Config::External::Mapper::LocationExpander, feature_category: :pipeline_authoring do + include RepoHelpers + + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { project.owner } + + let(:sha) { project.commit.sha } + + let(:context) do + Gitlab::Ci::Config::External::Context.new(project: project, user: user, sha: sha) + end + + subject(:location_expander) { described_class.new(context) } + + describe '#process' do + subject(:process) { location_expander.process(locations) } + + context 'when there are project files' do + let(:locations) do + [{ project: 'gitlab-org/gitlab-1', file: ['builds.yml', 'tests.yml'] }, + { project: 'gitlab-org/gitlab-2', file: 'deploy.yml' }] + end + + it 'returns expanded locations' do + is_expected.to eq( + [{ project: 'gitlab-org/gitlab-1', file: 'builds.yml' }, + { project: 'gitlab-org/gitlab-1', file: 'tests.yml' }, + { project: 'gitlab-org/gitlab-2', file: 'deploy.yml' }] + ) + end + end + + context 'when there are local files' do + let(:locations) do + [{ local: 'builds/*.yml' }, + { local: 'tests.yml' }] + end + + let(:project_files) do + { 'builds/1.yml' => 'a', 'builds/2.yml' => 'b', 'tests.yml' => 'c' } + end + + around do |example| + create_and_delete_files(project, project_files) do + example.run + end + end + + it 'returns expanded locations' do + is_expected.to eq( + [{ local: 'builds/1.yml' }, + { local: 'builds/2.yml' }, + { local: 'tests.yml' }] + ) + end + end + + context 'when there are other files' do + let(:locations) do + [{ remote: 'https://gitlab.com/gitlab-org/gitlab-ce/raw/master/.gitlab-ci.yml' }] + end + + it 'returns the same location' do + is_expected.to eq(locations) + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/external/mapper/matcher_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/matcher_spec.rb new file mode 100644 index 00000000000..5f321a696c9 --- /dev/null +++ b/spec/lib/gitlab/ci/config/external/mapper/matcher_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Config::External::Mapper::Matcher, feature_category: :pipeline_authoring do + let_it_be(:variables) do + Gitlab::Ci::Variables::Collection.new.tap do |variables| + variables.append(key: 'A_MASKED_VAR', value: 'this-is-secret', masked: true) + end + end + + let_it_be(:context) do + Gitlab::Ci::Config::External::Context.new(variables: variables) + end + + subject(:matcher) { described_class.new(context) } + + describe '#process' do + let(:locations) do + [{ local: 'file.yml' }, + { file: 'file.yml', project: 'namespace/project' }, + { remote: 'https://example.com/.gitlab-ci.yml' }, + { template: 'file.yml' }, + { artifact: 'generated.yml', job: 'test' }] + end + + subject(:process) { matcher.process(locations) } + + it 'returns an array of file objects' do + is_expected.to contain_exactly( + an_instance_of(Gitlab::Ci::Config::External::File::Local), + an_instance_of(Gitlab::Ci::Config::External::File::Project), + an_instance_of(Gitlab::Ci::Config::External::File::Remote), + an_instance_of(Gitlab::Ci::Config::External::File::Template), + an_instance_of(Gitlab::Ci::Config::External::File::Artifact) + ) + end + + context 'when a location is not valid' do + let(:locations) { [{ invalid: 'file.yml' }] } + + it 'raises an error' do + expect { process }.to raise_error( + Gitlab::Ci::Config::External::Mapper::AmbigiousSpecificationError, + '`{"invalid":"file.yml"}` does not have a valid subkey for include. ' \ + 'Valid subkeys are: `local`, `project`, `remote`, `template`, `artifact`' + ) + end + + context 'when the invalid location includes a masked variable' do + let(:locations) { [{ invalid: 'this-is-secret.yml' }] } + + it 'raises an error with a masked sentence' do + expect { process }.to raise_error( + Gitlab::Ci::Config::External::Mapper::AmbigiousSpecificationError, + '`{"invalid":"xxxxxxxxxxxxxx.yml"}` does not have a valid subkey for include. ' \ + 'Valid subkeys are: `local`, `project`, `remote`, `template`, `artifact`' + ) + end + end + end + + context 'when a location is ambiguous' do + let(:locations) { [{ local: 'file.yml', remote: 'https://example.com/.gitlab-ci.yml' }] } + + it 'raises an error' do + expect { process }.to raise_error( + Gitlab::Ci::Config::External::Mapper::AmbigiousSpecificationError, + "Each include must use only one of: `local`, `project`, `remote`, `template`, `artifact`" + ) + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/external/mapper/normalizer_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/normalizer_spec.rb new file mode 100644 index 00000000000..709c234253b --- /dev/null +++ b/spec/lib/gitlab/ci/config/external/mapper/normalizer_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Config::External::Mapper::Normalizer, feature_category: :pipeline_authoring do + let_it_be(:variables) do + Gitlab::Ci::Variables::Collection.new.tap do |variables| + variables.append(key: 'VARIABLE1', value: 'config') + variables.append(key: 'VARIABLE2', value: 'https://example.com') + end + end + + let_it_be(:context) do + Gitlab::Ci::Config::External::Context.new(variables: variables) + end + + subject(:normalizer) { described_class.new(context) } + + describe '#process' do + let(:locations) do + ['https://example.com/.gitlab-ci.yml', + 'config/.gitlab-ci.yml', + { local: 'config/.gitlab-ci.yml' }, + { remote: 'https://example.com/.gitlab-ci.yml' }, + { template: 'Template.gitlab-ci.yml' }, + '$VARIABLE1/.gitlab-ci.yml', + '$VARIABLE2/.gitlab-ci.yml'] + end + + subject(:process) { normalizer.process(locations) } + + it 'converts locations to canonical form' do + is_expected.to eq( + [{ remote: 'https://example.com/.gitlab-ci.yml' }, + { local: 'config/.gitlab-ci.yml' }, + { local: 'config/.gitlab-ci.yml' }, + { remote: 'https://example.com/.gitlab-ci.yml' }, + { template: 'Template.gitlab-ci.yml' }, + { local: 'config/.gitlab-ci.yml' }, + { remote: 'https://example.com/.gitlab-ci.yml' }] + ) + end + end +end diff --git a/spec/lib/gitlab/ci/config/external/mapper/variables_expander_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/variables_expander_spec.rb new file mode 100644 index 00000000000..f7454dcd4be --- /dev/null +++ b/spec/lib/gitlab/ci/config/external/mapper/variables_expander_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Config::External::Mapper::VariablesExpander, feature_category: :pipeline_authoring do + let_it_be(:variables) do + Gitlab::Ci::Variables::Collection.new.tap do |variables| + variables.append(key: 'VARIABLE1', value: 'hello') + end + end + + let_it_be(:context) do + Gitlab::Ci::Config::External::Context.new(variables: variables) + end + + subject(:variables_expander) { described_class.new(context) } + + describe '#process' do + subject(:process) { variables_expander.process(locations) } + + context 'when locations are strings' do + let(:locations) { ['$VARIABLE1.gitlab-ci.yml'] } + + it 'expands variables' do + is_expected.to eq(['hello.gitlab-ci.yml']) + end + end + + context 'when locations are hashes' do + let(:locations) { [{ local: '$VARIABLE1.gitlab-ci.yml' }] } + + it 'expands variables' do + is_expected.to eq([{ local: 'hello.gitlab-ci.yml' }]) + end + end + + context 'when locations are arrays' do + let(:locations) { [{ local: ['$VARIABLE1.gitlab-ci.yml'] }] } + + it 'expands variables' do + is_expected.to eq([{ local: ['hello.gitlab-ci.yml'] }]) + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb new file mode 100644 index 00000000000..7c7252c6b0e --- /dev/null +++ b/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb @@ -0,0 +1,137 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Config::External::Mapper::Verifier, feature_category: :pipeline_authoring do + include RepoHelpers + include StubRequests + + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { project.owner } + + let(:context) do + Gitlab::Ci::Config::External::Context.new(project: project, user: user, sha: project.commit.id) + end + + let(:remote_url) { 'https://gitlab.com/gitlab-org/gitlab-foss/blob/1234/.gitlab-ci-1.yml' } + + let(:project_files) do + { + 'myfolder/file1.yml' => <<~YAML, + my_build: + script: echo Hello World + YAML + 'myfolder/file2.yml' => <<~YAML, + my_test: + script: echo Hello World + YAML + 'nested_configs.yml' => <<~YAML + include: + - local: myfolder/file1.yml + - local: myfolder/file2.yml + - remote: #{remote_url} + YAML + } + end + + around(:all) do |example| + create_and_delete_files(project, project_files) do + example.run + end + end + + before do + stub_full_request(remote_url).to_return( + body: <<~YAML + remote_test: + script: echo Hello World + YAML + ) + end + + subject(:verifier) { described_class.new(context) } + + describe '#process' do + subject(:process) { verifier.process(files) } + + context 'when files are local' do + let(:files) do + [ + Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/file1.yml' }, context), + Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/file2.yml' }, context) + ] + end + + it 'returns an array of file objects' do + expect(process.map(&:location)).to contain_exactly('myfolder/file1.yml', 'myfolder/file2.yml') + end + + it 'adds files to the expandset' do + expect { process }.to change { context.expandset.count }.by(2) + end + end + + context 'when a file includes other files' do + let(:files) do + [ + Gitlab::Ci::Config::External::File::Local.new({ local: 'nested_configs.yml' }, context) + ] + end + + it 'returns an array of file objects with combined hash' do + expect(process.map(&:to_hash)).to contain_exactly( + { my_build: { script: 'echo Hello World' }, + my_test: { script: 'echo Hello World' }, + remote_test: { script: 'echo Hello World' } } + ) + end + end + + context 'when there is an invalid file' do + let(:files) do + [ + Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/invalid.yml' }, context) + ] + end + + it 'adds an error to the file' do + expect(process.first.errors).to include("Local file `myfolder/invalid.yml` does not exist!") + end + end + + context 'when max_includes is exceeded' do + context 'when files are nested' do + let(:files) do + [ + Gitlab::Ci::Config::External::File::Local.new({ local: 'nested_configs.yml' }, context) + ] + end + + before do + allow(context).to receive(:max_includes).and_return(1) + end + + it 'raises Processor::IncludeError' do + expect { process }.to raise_error(Gitlab::Ci::Config::External::Processor::IncludeError) + end + end + + context 'when files are not nested' do + let(:files) do + [ + Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/file1.yml' }, context), + Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/file2.yml' }, context) + ] + end + + before do + allow(context).to receive(:max_includes).and_return(1) + end + + it 'raises Mapper::TooManyIncludesError' do + expect { process }.to raise_error(Gitlab::Ci::Config::External::Mapper::TooManyIncludesError) + end + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/external/mapper_spec.rb b/spec/lib/gitlab/ci/config/external/mapper_spec.rb index 759f9830f87..b7e58d4dfa1 100644 --- a/spec/lib/gitlab/ci/config/external/mapper_spec.rb +++ b/spec/lib/gitlab/ci/config/external/mapper_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Config::External::Mapper, feature_category: :pipeline_authoring do +# This will be removed with FF ci_refactoring_external_mapper and moved to below. +RSpec.shared_context 'gitlab_ci_config_external_mapper' do include StubRequests include RepoHelpers @@ -39,7 +40,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper, feature_category: :pipeline it 'propagates the pipeline logger' do process - fetch_content_log_count = mapper + fetch_content_log_count = context .logger .observations_hash .dig(key, 'count') @@ -232,7 +233,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper, feature_category: :pipeline it 'has expanset with one' do process - expect(mapper.expandset.size).to eq(1) + expect(context.expandset.size).to eq(1) end end @@ -457,8 +458,20 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper, feature_category: :pipeline it 'has expanset with two' do process - expect(mapper.expandset.size).to eq(2) + expect(context.expandset.size).to eq(2) end end end end + +RSpec.describe Gitlab::Ci::Config::External::Mapper, feature_category: :pipeline_authoring do + it_behaves_like 'gitlab_ci_config_external_mapper' + + context 'when the FF ci_refactoring_external_mapper is disabled' do + before do + stub_feature_flags(ci_refactoring_external_mapper: false) + end + + it_behaves_like 'gitlab_ci_config_external_mapper' + end +end diff --git a/spec/lib/gitlab/database/reindexing_spec.rb b/spec/lib/gitlab/database/reindexing_spec.rb index 4c98185e780..fa26aa59329 100644 --- a/spec/lib/gitlab/database/reindexing_spec.rb +++ b/spec/lib/gitlab/database/reindexing_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Database::Reindexing do +RSpec.describe Gitlab::Database::Reindexing, feature_category: :database do include ExclusiveLeaseHelpers include Database::DatabaseHelpers diff --git a/spec/lib/gitlab/database/transaction/context_spec.rb b/spec/lib/gitlab/database/transaction/context_spec.rb index 33a47150060..1681098e20c 100644 --- a/spec/lib/gitlab/database/transaction/context_spec.rb +++ b/spec/lib/gitlab/database/transaction/context_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Database::Transaction::Context do +RSpec.describe Gitlab::Database::Transaction::Context, feature_category: :database do subject { described_class.new } let(:data) { subject.context } diff --git a/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb b/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb index 960e2ed77fb..1b8da0b380b 100644 --- a/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb +++ b/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require 'json' require 'tempfile' -RSpec.describe Gitlab::Git::RuggedImpl::UseRugged do +RSpec.describe Gitlab::Git::RuggedImpl::UseRugged, feature_category: :gitlay do let(:project) { create(:project, :repository) } let(:repository) { project.repository } let(:feature_flag_name) { wrapper.rugged_feature_keys.first } diff --git a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb index 1444897e136..c794694f08b 100644 --- a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do +RSpec.describe Gitlab::ImportExport::Group::TreeRestorer, feature: :subgroups do include ImportExport::CommonUtil shared_examples 'group restoration' do diff --git a/spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb b/spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb index fa50adb4e4f..6673cc50d67 100644 --- a/spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb +++ b/spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Metrics::Exporter::BaseExporter do +RSpec.describe Gitlab::Metrics::Exporter::BaseExporter, feature_category: :application_performance do let(:settings) { double('settings') } let(:log_enabled) { false } let(:exporter) { described_class.new(settings, log_enabled: log_enabled, log_file: 'test_exporter.log') } diff --git a/spec/lib/gitlab/process_supervisor_spec.rb b/spec/lib/gitlab/process_supervisor_spec.rb index 8356197805c..18de5053362 100644 --- a/spec/lib/gitlab/process_supervisor_spec.rb +++ b/spec/lib/gitlab/process_supervisor_spec.rb @@ -2,7 +2,7 @@ require_relative '../../../lib/gitlab/process_supervisor' -RSpec.describe Gitlab::ProcessSupervisor do +RSpec.describe Gitlab::ProcessSupervisor, feature_category: :application_performance do let(:health_check_interval_seconds) { 0.1 } let(:check_terminate_interval_seconds) { 1 } let(:forwarded_signals) { [] } diff --git a/spec/lib/gitlab/redis/multi_store_spec.rb b/spec/lib/gitlab/redis/multi_store_spec.rb index 207fe28e84e..0e7eedf66b1 100644 --- a/spec/lib/gitlab/redis/multi_store_spec.rb +++ b/spec/lib/gitlab/redis/multi_store_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Redis::MultiStore do +RSpec.describe Gitlab::Redis::MultiStore, feature_category: :redis do using RSpec::Parameterized::TableSyntax let_it_be(:redis_store_class) do diff --git a/spec/lib/gitlab/slash_commands/deploy_spec.rb b/spec/lib/gitlab/slash_commands/deploy_spec.rb index 5af234ff88e..94a95fb417f 100644 --- a/spec/lib/gitlab/slash_commands/deploy_spec.rb +++ b/spec/lib/gitlab/slash_commands/deploy_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::SlashCommands::Deploy do +RSpec.describe Gitlab::SlashCommands::Deploy, feature_category: :team_planning do describe '#execute' do let(:project) { create(:project, :repository) } let(:user) { create(:user) } |