diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-07 00:12:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-07 00:12:16 +0300 |
commit | 87598f1576cc7b3e1071a83d70778a51009b853b (patch) | |
tree | 42a1e678a3f9abf870d1cc88ecf536375f889b12 /spec/lib/bulk_imports | |
parent | 30e5ae4c2b9c1674dc222e4bde0daa3f9795782e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/bulk_imports')
3 files changed, 98 insertions, 3 deletions
diff --git a/spec/lib/bulk_imports/projects/graphql/get_repository_query_spec.rb b/spec/lib/bulk_imports/projects/graphql/get_repository_query_spec.rb new file mode 100644 index 00000000000..4dba81dc0d2 --- /dev/null +++ b/spec/lib/bulk_imports/projects/graphql/get_repository_query_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Projects::Graphql::GetRepositoryQuery do + describe 'query repository based on full_path' do + let(:entity) { double(source_full_path: 'test', bulk_import: nil) } + let(:tracker) { double(entity: entity) } + let(:context) { BulkImports::Pipeline::Context.new(tracker) } + + it 'returns project repository url' do + expect(described_class.to_s).to include('httpUrlToRepo') + end + + it 'queries project based on source_full_path' do + expected = { full_path: entity.source_full_path } + + expect(described_class.variables(context)).to eq(expected) + end + end +end diff --git a/spec/lib/bulk_imports/projects/pipelines/repository_pipeline_spec.rb b/spec/lib/bulk_imports/projects/pipelines/repository_pipeline_spec.rb new file mode 100644 index 00000000000..af39ec7a11c --- /dev/null +++ b/spec/lib/bulk_imports/projects/pipelines/repository_pipeline_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Projects::Pipelines::RepositoryPipeline do + describe '#run' do + let_it_be(:user) { create(:user) } + let_it_be(:parent) { create(:project) } + let_it_be(:bulk_import) { create(:bulk_import, user: user) } + let_it_be(:bulk_import_configuration) { create(:bulk_import_configuration, bulk_import: bulk_import) } + + let_it_be(:entity) do + create( + :bulk_import_entity, + :project_entity, + bulk_import: bulk_import, + source_full_path: 'source/full/path', + destination_name: 'My Destination Repository', + destination_namespace: parent.full_path, + project: parent + ) + end + + let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) } + let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) } + + context 'successfully imports repository' do + let(:project_data) do + { + 'httpUrlToRepo' => 'http://test.git' + } + end + + subject { described_class.new(context) } + + it 'imports new repository into destination project' do + allow_next_instance_of(BulkImports::Common::Extractors::GraphqlExtractor) do |extractor| + allow(extractor).to receive(:extract).and_return(BulkImports::Pipeline::ExtractedData.new(data: project_data)) + end + + expect_next_instance_of(Gitlab::GitalyClient::RepositoryService) do |repository_service| + url = project_data['httpUrlToRepo'].sub("://", "://oauth2:#{bulk_import_configuration.access_token}@") + expect(repository_service).to receive(:import_repository).with(url).and_return 0 + end + + subject.run + end + end + + context 'blocked local networks' do + let(:project_data) do + { + 'httpUrlToRepo' => 'http://localhost/foo.git' + } + end + + before do + allow(Gitlab.config.gitlab).to receive(:host).and_return('notlocalhost.gitlab.com') + allow(Gitlab::CurrentSettings).to receive(:allow_local_requests_from_web_hooks_and_services?).and_return(false) + allow_next_instance_of(BulkImports::Common::Extractors::GraphqlExtractor) do |extractor| + allow(extractor).to receive(:extract).and_return(BulkImports::Pipeline::ExtractedData.new(data: project_data)) + end + end + + subject { described_class.new(context) } + + it 'imports new repository into destination project' do + subject.run + expect(context.entity.failed?).to be_truthy + end + end + end +end diff --git a/spec/lib/bulk_imports/projects/stage_spec.rb b/spec/lib/bulk_imports/projects/stage_spec.rb index 0109b65427f..61f1be1a35d 100644 --- a/spec/lib/bulk_imports/projects/stage_spec.rb +++ b/spec/lib/bulk_imports/projects/stage_spec.rb @@ -6,9 +6,10 @@ RSpec.describe BulkImports::Projects::Stage do let(:pipelines) do [ [0, BulkImports::Projects::Pipelines::ProjectPipeline], - [1, BulkImports::Common::Pipelines::LabelsPipeline], - [2, BulkImports::Projects::Pipelines::IssuesPipeline], - [3, BulkImports::Common::Pipelines::EntityFinisher] + [1, BulkImports::Projects::Pipelines::RepositoryPipeline], + [2, BulkImports::Common::Pipelines::LabelsPipeline], + [3, BulkImports::Projects::Pipelines::IssuesPipeline], + [4, BulkImports::Common::Pipelines::EntityFinisher] ] end |