diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-27 06:08:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-27 06:08:03 +0300 |
commit | c258498bd253e0dbb038d51f237cee1ebf0d0f56 (patch) | |
tree | 2fafd83d60bf1b104b2bd39b199c79ddf91564a7 /spec | |
parent | 17f6b320a11fc5bc1261994a7a93b34096e365e3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
8 files changed, 285 insertions, 128 deletions
diff --git a/spec/frontend/vue_mr_widget/components/mr_widget_suggest_pipeline_spec.js b/spec/frontend/vue_mr_widget/components/mr_widget_suggest_pipeline_spec.js index 8e710b6d65f..352bc1a08ea 100644 --- a/spec/frontend/vue_mr_widget/components/mr_widget_suggest_pipeline_spec.js +++ b/spec/frontend/vue_mr_widget/components/mr_widget_suggest_pipeline_spec.js @@ -71,7 +71,7 @@ describe('MRWidgetSuggestPipeline', () => { const button = findOkBtn(); expect(button.exists()).toBe(true); - expect(button.classes('btn-info')).toEqual(true); + expect(button.classes('btn-confirm')).toEqual(true); expect(button.attributes('href')).toBe(suggestProps.pipelinePath); }); diff --git a/spec/lib/bulk_imports/groups/stage_spec.rb b/spec/lib/bulk_imports/groups/stage_spec.rb index 8ce25ff87d7..528d65615b1 100644 --- a/spec/lib/bulk_imports/groups/stage_spec.rb +++ b/spec/lib/bulk_imports/groups/stage_spec.rb @@ -4,47 +4,86 @@ require 'spec_helper' RSpec.describe BulkImports::Groups::Stage do let(:ancestor) { create(:group) } - let(:group) { create(:group, parent: ancestor) } + let(:group) { build(:group, parent: ancestor) } let(:bulk_import) { build(:bulk_import) } - let(:entity) { build(:bulk_import_entity, bulk_import: bulk_import, group: group, destination_namespace: ancestor.full_path) } - - let(:pipelines) do - [ - [0, BulkImports::Groups::Pipelines::GroupPipeline], - [1, BulkImports::Groups::Pipelines::GroupAttributesPipeline], - [1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline], - [1, BulkImports::Groups::Pipelines::NamespaceSettingsPipeline], - [1, BulkImports::Common::Pipelines::MembersPipeline], - [1, BulkImports::Common::Pipelines::LabelsPipeline], - [1, BulkImports::Common::Pipelines::MilestonesPipeline], - [1, BulkImports::Common::Pipelines::BadgesPipeline], - [2, BulkImports::Common::Pipelines::BoardsPipeline], - [2, BulkImports::Common::Pipelines::UploadsPipeline] - ] + let(:entity) do + build(:bulk_import_entity, bulk_import: bulk_import, group: group, destination_namespace: ancestor.full_path) end it 'raises error when initialized without a BulkImport' do - expect { described_class.new({}) }.to raise_error(ArgumentError, 'Expected an argument of type ::BulkImports::Entity') + expect { described_class.new({}) }.to raise_error( + ArgumentError, 'Expected an argument of type ::BulkImports::Entity' + ) end - describe '.pipelines' do - it 'list all the pipelines with their stage number, ordered by stage' do - expect(described_class.new(entity).pipelines & pipelines).to contain_exactly(*pipelines) - expect(described_class.new(entity).pipelines.last.last).to eq(BulkImports::Common::Pipelines::EntityFinisher) + describe '#pipelines' do + it 'lists all the pipelines' do + pipelines = described_class.new(entity).pipelines + + expect(pipelines).to include( + hash_including({ + pipeline: BulkImports::Groups::Pipelines::GroupPipeline, + stage: 0 + }), + hash_including({ + pipeline: BulkImports::Groups::Pipelines::GroupAttributesPipeline, + stage: 1 + }) + ) + expect(pipelines.last).to match(hash_including({ pipeline: BulkImports::Common::Pipelines::EntityFinisher })) + end + + it 'only has pipelines with valid keys' do + pipeline_keys = described_class.new(entity).pipelines.collect(&:keys).flatten.uniq + allowed_keys = %i[pipeline stage minimum_source_version maximum_source_version] + + expect(pipeline_keys - allowed_keys).to be_empty + end + + it 'only has pipelines with valid versions' do + pipelines = described_class.new(entity).pipelines + minimum_source_versions = pipelines.collect { _1[:minimum_source_version] }.flatten.compact + maximum_source_versions = pipelines.collect { _1[:maximum_source_version] }.flatten.compact + version_regex = /^(\d+)\.(\d+)\.0$/ + + expect(minimum_source_versions.all? { version_regex =~ _1 }).to eq(true) + expect(maximum_source_versions.all? { version_regex =~ _1 }).to eq(true) + end + + context 'when stages are out of order in the config hash' do + it 'lists all the pipelines ordered by stage' do + allow_next_instance_of(BulkImports::Groups::Stage) do |stage| + allow(stage).to receive(:config).and_return( + { + a: { stage: 2 }, + b: { stage: 1 }, + c: { stage: 0 }, + d: { stage: 2 } + } + ) + end + + expected_stages = described_class.new(entity).pipelines.collect { _1[:stage] } + expect(expected_stages).to eq([0, 1, 2, 2]) + end end context 'when bulk_import_projects feature flag is enabled' do it 'includes project entities pipeline' do stub_feature_flags(bulk_import_projects: true) - expect(described_class.new(entity).pipelines).to include([1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline]) + expect(described_class.new(entity).pipelines).to include( + hash_including({ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline }) + ) end context 'when feature flag is enabled on root ancestor level' do it 'includes project entities pipeline' do stub_feature_flags(bulk_import_projects: ancestor) - expect(described_class.new(entity).pipelines).to include([1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline]) + expect(described_class.new(entity).pipelines).to include( + hash_including({ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline }) + ) end end @@ -54,7 +93,9 @@ RSpec.describe BulkImports::Groups::Stage do entity = create(:bulk_import_entity, destination_namespace: '') - expect(described_class.new(entity).pipelines).to include([1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline]) + expect(described_class.new(entity).pipelines).to include( + hash_including({ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline }) + ) end end end @@ -63,7 +104,9 @@ RSpec.describe BulkImports::Groups::Stage do it 'does not include project entities pipeline' do stub_feature_flags(bulk_import_projects: false) - expect(described_class.new(entity).pipelines.flatten).not_to include(BulkImports::Groups::Pipelines::ProjectEntitiesPipeline) + expect(described_class.new(entity).pipelines).not_to include( + hash_including({ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline }) + ) end end end diff --git a/spec/lib/bulk_imports/projects/stage_spec.rb b/spec/lib/bulk_imports/projects/stage_spec.rb index abfc4e1de04..fc670d10655 100644 --- a/spec/lib/bulk_imports/projects/stage_spec.rb +++ b/spec/lib/bulk_imports/projects/stage_spec.rb @@ -2,39 +2,7 @@ require 'spec_helper' -# Any new stages must be added to -# `ee/spec/lib/ee/bulk_imports/projects/stage_spec.rb` as well. RSpec.describe BulkImports::Projects::Stage do - let(:pipelines) do - [ - [0, BulkImports::Projects::Pipelines::ProjectPipeline], - [1, BulkImports::Projects::Pipelines::RepositoryPipeline], - [1, BulkImports::Projects::Pipelines::ProjectAttributesPipeline], - [2, BulkImports::Common::Pipelines::LabelsPipeline], - [2, BulkImports::Common::Pipelines::MilestonesPipeline], - [2, BulkImports::Common::Pipelines::BadgesPipeline], - [3, BulkImports::Projects::Pipelines::IssuesPipeline], - [3, BulkImports::Projects::Pipelines::SnippetsPipeline], - [4, BulkImports::Projects::Pipelines::SnippetsRepositoryPipeline], - [4, BulkImports::Common::Pipelines::BoardsPipeline], - [4, BulkImports::Projects::Pipelines::MergeRequestsPipeline], - [4, BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline], - [4, BulkImports::Projects::Pipelines::ProtectedBranchesPipeline], - [4, BulkImports::Projects::Pipelines::ProjectFeaturePipeline], - [4, BulkImports::Projects::Pipelines::ContainerExpirationPolicyPipeline], - [4, BulkImports::Projects::Pipelines::ServiceDeskSettingPipeline], - [4, BulkImports::Projects::Pipelines::ReleasesPipeline], - [5, BulkImports::Projects::Pipelines::CiPipelinesPipeline], - [5, BulkImports::Common::Pipelines::WikiPipeline], - [5, BulkImports::Common::Pipelines::UploadsPipeline], - [5, BulkImports::Common::Pipelines::LfsObjectsPipeline], - [5, BulkImports::Projects::Pipelines::DesignBundlePipeline], - [5, BulkImports::Projects::Pipelines::AutoDevopsPipeline], - [5, BulkImports::Projects::Pipelines::PipelineSchedulesPipeline], - [6, BulkImports::Common::Pipelines::EntityFinisher] - ] - end - subject do entity = build(:bulk_import_entity, :project_entity) @@ -42,9 +10,49 @@ RSpec.describe BulkImports::Projects::Stage do end describe '#pipelines' do - it 'list all the pipelines with their stage number, ordered by stage' do - expect(subject.pipelines & pipelines).to contain_exactly(*pipelines) - expect(subject.pipelines.last.last).to eq(BulkImports::Common::Pipelines::EntityFinisher) + it 'list all the pipelines' do + pipelines = subject.pipelines + + expect(pipelines).to include( + hash_including({ stage: 0, pipeline: BulkImports::Projects::Pipelines::ProjectPipeline }), + hash_including({ stage: 1, pipeline: BulkImports::Projects::Pipelines::RepositoryPipeline }) + ) + expect(pipelines.last).to match(hash_including({ pipeline: BulkImports::Common::Pipelines::EntityFinisher })) + end + + it 'only have pipelines with valid keys' do + pipeline_keys = subject.pipelines.collect(&:keys).flatten.uniq + allowed_keys = %i[pipeline stage minimum_source_version maximum_source_version] + + expect(pipeline_keys - allowed_keys).to be_empty + end + + it 'only has pipelines with valid versions' do + pipelines = subject.pipelines + minimum_source_versions = pipelines.collect { _1[:minimum_source_version] }.flatten.compact + maximum_source_versions = pipelines.collect { _1[:maximum_source_version] }.flatten.compact + version_regex = /^(\d+)\.(\d+)\.0$/ + + expect(minimum_source_versions.all? { version_regex =~ _1 }).to eq(true) + expect(maximum_source_versions.all? { version_regex =~ _1 }).to eq(true) + end + + context 'when stages are out of order in the config hash' do + it 'list all the pipelines ordered by stage' do + allow_next_instance_of(BulkImports::Projects::Stage) do |stage| + allow(stage).to receive(:config).and_return( + { + a: { stage: 2 }, + b: { stage: 1 }, + c: { stage: 0 }, + d: { stage: 2 } + } + ) + end + + expected_stages = subject.pipelines.collect { _1[:stage] } + expect(expected_stages).to eq([0, 1, 2, 2]) + end end end end diff --git a/spec/models/bulk_imports/entity_spec.rb b/spec/models/bulk_imports/entity_spec.rb index 6f6a7c9bcd8..874009d552a 100644 --- a/spec/models/bulk_imports/entity_spec.rb +++ b/spec/models/bulk_imports/entity_spec.rb @@ -160,7 +160,7 @@ RSpec.describe BulkImports::Entity, type: :model do it 'returns group pipelines' do entity = build(:bulk_import_entity, :group_entity) - expect(entity.pipelines.flatten).to include(BulkImports::Groups::Pipelines::GroupPipeline) + expect(entity.pipelines.collect { _1[:pipeline] }).to include(BulkImports::Groups::Pipelines::GroupPipeline) end end @@ -168,29 +168,7 @@ RSpec.describe BulkImports::Entity, type: :model do it 'returns project pipelines' do entity = build(:bulk_import_entity, :project_entity) - expect(entity.pipelines.flatten).to include(BulkImports::Projects::Pipelines::ProjectPipeline) - end - end - end - - describe '#create_pipeline_trackers!' do - context 'when entity is group' do - it 'creates trackers for group entity' do - entity = create(:bulk_import_entity, :group_entity) - entity.create_pipeline_trackers! - - expect(entity.trackers.count).to eq(BulkImports::Groups::Stage.new(entity).pipelines.count) - expect(entity.trackers.map(&:pipeline_name)).to include(BulkImports::Groups::Pipelines::GroupPipeline.to_s) - end - end - - context 'when entity is project' do - it 'creates trackers for project entity' do - entity = create(:bulk_import_entity, :project_entity) - entity.create_pipeline_trackers! - - expect(entity.trackers.count).to eq(BulkImports::Projects::Stage.new(entity).pipelines.count) - expect(entity.trackers.map(&:pipeline_name)).to include(BulkImports::Projects::Pipelines::ProjectPipeline.to_s) + expect(entity.pipelines.collect { _1[:pipeline] }).to include(BulkImports::Projects::Pipelines::ProjectPipeline) end end end diff --git a/spec/models/bulk_imports/tracker_spec.rb b/spec/models/bulk_imports/tracker_spec.rb index 0b6f692a477..1aa76d4dadd 100644 --- a/spec/models/bulk_imports/tracker_spec.rb +++ b/spec/models/bulk_imports/tracker_spec.rb @@ -67,7 +67,7 @@ RSpec.describe BulkImports::Tracker, type: :model do describe '#pipeline_class' do it 'returns the pipeline class' do entity = create(:bulk_import_entity) - pipeline_class = BulkImports::Groups::Stage.new(entity).pipelines.first[1] + pipeline_class = BulkImports::Groups::Stage.new(entity).pipelines.first[:pipeline] tracker = create(:bulk_import_tracker, pipeline_name: pipeline_class) expect(tracker.pipeline_class).to eq(pipeline_class) diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index f0779f1c57c..292f1c395f5 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -77,46 +77,6 @@ RSpec.describe MergeRequestWidgetEntity do .to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.diff") end - describe 'codequality report artifacts', :request_store do - let(:merge_base_pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) } - - before do - project.add_developer(user) - - allow(resource).to receive_messages( - merge_base_pipeline: merge_base_pipeline, - base_pipeline: pipeline, - head_pipeline: pipeline - ) - end - - context 'with report artifacts' do - let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) } - let(:generic_job_id) { pipeline.builds.first.id } - let(:merge_base_job_id) { merge_base_pipeline.builds.first.id } - - it 'has head_path and base_path entries' do - expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality") - expect(subject[:codeclimate][:base_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality") - end - - context 'on pipelines for merged results' do - let(:pipeline) { create(:ci_pipeline, :merged_result_pipeline, :with_codequality_reports, project: project) } - - it 'returns URLs from the head_pipeline and merge_base_pipeline' do - expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality") - expect(subject[:codeclimate][:base_path]).to include("/jobs/#{merge_base_job_id}/artifacts/download?file_type=codequality") - end - end - end - - context 'without artifacts' do - it 'does not have data entry' do - expect(subject).not_to include(:codeclimate) - end - end - end - describe 'merge_request_add_ci_config_path' do let!(:project_auto_devops) { create(:project_auto_devops, :disabled, project: project) } diff --git a/spec/services/bulk_imports/create_pipeline_trackers_service_spec.rb b/spec/services/bulk_imports/create_pipeline_trackers_service_spec.rb new file mode 100644 index 00000000000..d7b00ba04ab --- /dev/null +++ b/spec/services/bulk_imports/create_pipeline_trackers_service_spec.rb @@ -0,0 +1,168 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::CreatePipelineTrackersService do + describe '#execute!' do + context 'when entity is group' do + it 'creates trackers for group entity' do + bulk_import = create(:bulk_import) + entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) + + described_class.new(entity).execute! + + expect(entity.trackers.to_a).to include( + have_attributes( + stage: 0, status_name: :created, relation: BulkImports::Groups::Pipelines::GroupPipeline.to_s + ), + have_attributes( + stage: 1, status_name: :created, relation: BulkImports::Groups::Pipelines::GroupAttributesPipeline.to_s + ) + ) + end + end + + context 'when entity is project' do + it 'creates trackers for project entity' do + bulk_import = create(:bulk_import) + entity = create(:bulk_import_entity, :project_entity, bulk_import: bulk_import) + + described_class.new(entity).execute! + + expect(entity.trackers.to_a).to include( + have_attributes( + stage: 0, status_name: :created, relation: BulkImports::Projects::Pipelines::ProjectPipeline.to_s + ), + have_attributes( + stage: 1, status_name: :created, relation: BulkImports::Projects::Pipelines::RepositoryPipeline.to_s + ) + ) + end + end + + context 'when tracker configuration has a minimum version defined' do + before do + allow_next_instance_of(BulkImports::Groups::Stage) do |stage| + allow(stage).to receive(:config).and_return( + { + pipeline1: { pipeline: 'PipelineClass1', stage: 0 }, + pipeline2: { pipeline: 'PipelineClass2', stage: 1, minimum_source_version: '14.10.0' }, + pipeline3: { pipeline: 'PipelineClass3', stage: 1, minimum_source_version: '15.0.0' }, + pipeline5: { pipeline: 'PipelineClass4', stage: 1, minimum_source_version: '15.1.0' }, + pipeline6: { pipeline: 'PipelineClass5', stage: 1, minimum_source_version: '16.0.0' } + } + ) + end + end + + context 'when the source instance version is older than the tracker mininum version' do + let_it_be(:bulk_import) { create(:bulk_import, source_version: '15.0.0') } + let_it_be(:entity) { create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) } + + it 'creates trackers as skipped if version requirement does not meet' do + described_class.new(entity).execute! + + expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly( + [:created, 'PipelineClass1'], + [:created, 'PipelineClass2'], + [:created, 'PipelineClass3'], + [:skipped, 'PipelineClass4'], + [:skipped, 'PipelineClass5'] + ) + end + + it 'logs an info message for the skipped pipelines' do + expect_next_instance_of(Gitlab::Import::Logger) do |logger| + expect(logger).to receive(:info).with({ + message: 'Pipeline skipped as source instance version not compatible with pipeline', + entity_id: entity.id, + pipeline_name: 'PipelineClass4', + minimum_source_version: '15.1.0', + maximum_source_version: nil, + source_version: '15.0.0' + }) + + expect(logger).to receive(:info).with({ + message: 'Pipeline skipped as source instance version not compatible with pipeline', + entity_id: entity.id, + pipeline_name: 'PipelineClass5', + minimum_source_version: '16.0.0', + maximum_source_version: nil, + source_version: '15.0.0' + }) + end + + described_class.new(entity).execute! + end + end + + context 'when the source instance version is undefined' do + it 'creates trackers as created' do + bulk_import = create(:bulk_import, source_version: nil) + entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) + + described_class.new(entity).execute! + + expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly( + [:created, 'PipelineClass1'], + [:created, 'PipelineClass2'], + [:created, 'PipelineClass3'], + [:created, 'PipelineClass4'], + [:created, 'PipelineClass5'] + ) + end + end + end + + context 'when tracker configuration has a maximum version defined' do + before do + allow_next_instance_of(BulkImports::Groups::Stage) do |stage| + allow(stage).to receive(:config).and_return( + { + pipeline1: { pipeline: 'PipelineClass1', stage: 0 }, + pipeline2: { pipeline: 'PipelineClass2', stage: 1, maximum_source_version: '14.10.0' }, + pipeline3: { pipeline: 'PipelineClass3', stage: 1, maximum_source_version: '15.0.0' }, + pipeline5: { pipeline: 'PipelineClass4', stage: 1, maximum_source_version: '15.1.0' }, + pipeline6: { pipeline: 'PipelineClass5', stage: 1, maximum_source_version: '16.0.0' } + } + ) + end + end + + context 'when the source instance version is older than the tracker maximum version' do + it 'creates trackers as skipped if version requirement does not meet' do + bulk_import = create(:bulk_import, source_version: '15.0.0') + entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) + + described_class.new(entity).execute! + + expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly( + [:created, 'PipelineClass1'], + [:skipped, 'PipelineClass2'], + [:created, 'PipelineClass3'], + [:created, 'PipelineClass4'], + [:created, 'PipelineClass5'] + ) + end + end + + context 'when the source instance version is a patch version' do + it 'creates trackers with the same status as the non-patch source version' do + bulk_import_1 = create(:bulk_import, source_version: '15.0.1') + entity_1 = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import_1) + + bulk_import_2 = create(:bulk_import, source_version: '15.0.0') + entity_2 = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import_2) + + described_class.new(entity_1).execute! + described_class.new(entity_2).execute! + + trackers_1 = entity_1.trackers.collect { |tracker| [tracker.status_name, tracker.relation] } + trackers_2 = entity_2.trackers.collect { |tracker| [tracker.status_name, tracker.relation] } + + expect(trackers_1).to eq(trackers_2) + end + end + end + end +end diff --git a/spec/workers/bulk_imports/pipeline_worker_spec.rb b/spec/workers/bulk_imports/pipeline_worker_spec.rb index 209ae8862b6..cbc7a146a54 100644 --- a/spec/workers/bulk_imports/pipeline_worker_spec.rb +++ b/spec/workers/bulk_imports/pipeline_worker_spec.rb @@ -24,7 +24,7 @@ RSpec.describe BulkImports::PipelineWorker do allow_next_instance_of(BulkImports::Groups::Stage) do |instance| allow(instance).to receive(:pipelines) - .and_return([[0, pipeline_class]]) + .and_return([{ stage: 0, pipeline: pipeline_class }]) end end @@ -253,7 +253,7 @@ RSpec.describe BulkImports::PipelineWorker do allow_next_instance_of(BulkImports::Groups::Stage) do |instance| allow(instance).to receive(:pipelines) - .and_return([[0, file_extraction_pipeline]]) + .and_return([{ stage: 0, pipeline: file_extraction_pipeline }]) end end |