Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/github_import/importer
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import/importer')
-rw-r--r--spec/lib/gitlab/github_import/importer/diff_note_importer_spec.rb8
-rw-r--r--spec/lib/gitlab/github_import/importer/issue_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/label_links_importer_spec.rb4
-rw-r--r--spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb26
-rw-r--r--spec/lib/gitlab/github_import/importer/note_importer_spec.rb8
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb28
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb120
-rw-r--r--spec/lib/gitlab/github_import/importer/repository_importer_spec.rb59
8 files changed, 93 insertions, 162 deletions
diff --git a/spec/lib/gitlab/github_import/importer/diff_note_importer_spec.rb b/spec/lib/gitlab/github_import/importer/diff_note_importer_spec.rb
index 9eea85526f5..0af840d2c10 100644
--- a/spec/lib/gitlab/github_import/importer/diff_note_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/diff_note_importer_spec.rb
@@ -36,7 +36,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do
describe '#execute' do
context 'when the merge request no longer exists' do
it 'does not import anything' do
- expect(Gitlab::Database).not_to receive(:bulk_insert)
+ expect(Gitlab::Database.main).not_to receive(:bulk_insert)
importer.execute
end
@@ -58,7 +58,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do
.to receive(:author_id_for)
.and_return([user.id, true])
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.with(
LegacyDiffNote.table_name,
@@ -89,7 +89,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do
.to receive(:author_id_for)
.and_return([project.creator_id, false])
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.with(
LegacyDiffNote.table_name,
@@ -133,7 +133,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do
.to receive(:author_id_for)
.and_return([project.creator_id, false])
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.and_raise(ActiveRecord::InvalidForeignKey, 'invalid foreign key')
diff --git a/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb
index fb826c987e1..0926000428c 100644
--- a/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb
@@ -190,7 +190,7 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueImporter, :clean_gitlab_redi
.with(issue.assignees[1])
.and_return(5)
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.with(
IssueAssignee.table_name,
diff --git a/spec/lib/gitlab/github_import/importer/label_links_importer_spec.rb b/spec/lib/gitlab/github_import/importer/label_links_importer_spec.rb
index 6d143f78c66..241a0fef600 100644
--- a/spec/lib/gitlab/github_import/importer/label_links_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/label_links_importer_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LabelLinksImporter do
.and_return(1)
freeze_time do
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.with(
LabelLink.table_name,
@@ -64,7 +64,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LabelLinksImporter do
.with('bug')
.and_return(nil)
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.with(LabelLink.table_name, [])
diff --git a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
index 8ee534734f0..a2c7d51214a 100644
--- a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
@@ -3,7 +3,8 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Importer::LfsObjectsImporter do
- let(:project) { double(:project, id: 4, import_source: 'foo/bar') }
+ let_it_be(:project) { create(:project, :import_started) }
+
let(:client) { double(:client) }
let(:download_link) { "http://www.gitlab.com/lfs_objects/oid" }
@@ -61,27 +62,12 @@ RSpec.describe Gitlab::GithubImport::Importer::LfsObjectsImporter do
.and_raise(exception)
end
- expect_next_instance_of(Gitlab::Import::Logger) do |logger|
- expect(logger)
- .to receive(:error)
- .with(
- message: 'importer failed',
- import_source: :github,
- project_id: project.id,
- parallel: false,
- importer: 'Gitlab::GithubImport::Importer::LfsObjectImporter',
- 'error.message': 'Invalid Project URL'
- )
- end
-
- expect(Gitlab::ErrorTracking)
- .to receive(:track_exception)
+ expect(Gitlab::Import::ImportFailureService)
+ .to receive(:track)
.with(
- exception,
- import_source: :github,
- parallel: false,
project_id: project.id,
- importer: 'Gitlab::GithubImport::Importer::LfsObjectImporter'
+ exception: exception,
+ error_source: 'Gitlab::GithubImport::Importer::LfsObjectImporter'
).and_call_original
importer.execute
diff --git a/spec/lib/gitlab/github_import/importer/note_importer_spec.rb b/spec/lib/gitlab/github_import/importer/note_importer_spec.rb
index ef0bb90db4a..820f46c7286 100644
--- a/spec/lib/gitlab/github_import/importer/note_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/note_importer_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe Gitlab::GithubImport::Importer::NoteImporter do
.with(github_note)
.and_return([user.id, true])
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.with(
Note.table_name,
@@ -71,7 +71,7 @@ RSpec.describe Gitlab::GithubImport::Importer::NoteImporter do
.with(github_note)
.and_return([project.creator_id, false])
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.with(
Note.table_name,
@@ -115,7 +115,7 @@ RSpec.describe Gitlab::GithubImport::Importer::NoteImporter do
context 'when the noteable does not exist' do
it 'does not import the note' do
- expect(Gitlab::Database).not_to receive(:bulk_insert)
+ expect(Gitlab::Database.main).not_to receive(:bulk_insert)
importer.execute
end
@@ -134,7 +134,7 @@ RSpec.describe Gitlab::GithubImport::Importer::NoteImporter do
.with(github_note)
.and_return([user.id, true])
- expect(Gitlab::Database)
+ expect(Gitlab::Database.main)
.to receive(:bulk_insert)
.and_raise(ActiveRecord::InvalidForeignKey, 'invalid foreign key')
diff --git a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
index 133d515246a..067b8b09516 100644
--- a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
@@ -148,7 +148,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
end
end
- shared_examples '#update_repository' do
+ describe '#update_repository' do
it 'updates the repository' do
importer = described_class.new(project, client)
@@ -162,6 +162,10 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
.to receive(:increment)
.and_call_original
+ expect(project.repository)
+ .to receive(:fetch_remote)
+ .with(url, forced: false, refmap: Gitlab::GithubImport.refmap)
+
freeze_time do
importer.update_repository
@@ -170,28 +174,6 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
end
end
- describe '#update_repository with :fetch_remote_params enabled' do
- before do
- stub_feature_flags(fetch_remote_params: true)
- expect(project.repository)
- .to receive(:fetch_remote)
- .with('github', forced: false, url: url, refmap: Gitlab::GithubImport.refmap)
- end
-
- it_behaves_like '#update_repository'
- end
-
- describe '#update_repository with :fetch_remote_params disabled' do
- before do
- stub_feature_flags(fetch_remote_params: false)
- expect(project.repository)
- .to receive(:fetch_remote)
- .with('github', forced: false)
- end
-
- it_behaves_like '#update_repository'
- end
-
describe '#update_repository?' do
let(:importer) { described_class.new(project, client) }
diff --git a/spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb
index 08be350f0f9..c5fa67e50aa 100644
--- a/spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb
@@ -27,100 +27,62 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsReviewsImporter do
end
describe '#each_object_to_import', :clean_gitlab_redis_cache do
- context 'when github_review_importer_query_only_unimported_merge_requests is enabled' do
- before do
- stub_feature_flags(github_review_importer_query_only_unimported_merge_requests: true)
- end
-
- let(:merge_request) do
- create(
- :merged_merge_request,
- iid: 999,
- source_project: project,
- target_project: project
- )
- end
-
- let(:review) { double(id: 1) }
-
- it 'fetches the pull requests reviews data' do
- page = double(objects: [review], number: 1)
-
- expect(review)
- .to receive(:merge_request_id=)
- .with(merge_request.id)
-
- expect(client)
- .to receive(:each_page)
- .exactly(:once) # ensure to be cached on the second call
- .with(:pull_request_reviews, 'github/repo', merge_request.iid, page: 1)
- .and_yield(page)
+ let(:merge_request) do
+ create(
+ :merged_merge_request,
+ iid: 999,
+ source_project: project,
+ target_project: project
+ )
+ end
- expect { |b| subject.each_object_to_import(&b) }
- .to yield_with_args(review)
+ let(:review) { double(id: 1) }
- subject.each_object_to_import {}
- end
+ it 'fetches the pull requests reviews data' do
+ page = double(objects: [review], number: 1)
- it 'skips cached pages' do
- Gitlab::GithubImport::PageCounter
- .new(project, "merge_request/#{merge_request.id}/pull_request_reviews")
- .set(2)
+ expect(review)
+ .to receive(:merge_request_id=)
+ .with(merge_request.id)
- expect(review).not_to receive(:merge_request_id=)
+ expect(client)
+ .to receive(:each_page)
+ .exactly(:once) # ensure to be cached on the second call
+ .with(:pull_request_reviews, 'github/repo', merge_request.iid, page: 1)
+ .and_yield(page)
- expect(client)
- .to receive(:each_page)
- .exactly(:once) # ensure to be cached on the second call
- .with(:pull_request_reviews, 'github/repo', merge_request.iid, page: 2)
+ expect { |b| subject.each_object_to_import(&b) }
+ .to yield_with_args(review)
- subject.each_object_to_import {}
- end
+ subject.each_object_to_import {}
+ end
- it 'skips cached merge requests' do
- Gitlab::Cache::Import::Caching.set_add(
- "github-importer/merge_request/already-imported/#{project.id}",
- merge_request.id
- )
+ it 'skips cached pages' do
+ Gitlab::GithubImport::PageCounter
+ .new(project, "merge_request/#{merge_request.id}/pull_request_reviews")
+ .set(2)
- expect(review).not_to receive(:merge_request_id=)
+ expect(review).not_to receive(:merge_request_id=)
- expect(client).not_to receive(:each_page)
+ expect(client)
+ .to receive(:each_page)
+ .exactly(:once) # ensure to be cached on the second call
+ .with(:pull_request_reviews, 'github/repo', merge_request.iid, page: 2)
- subject.each_object_to_import {}
- end
+ subject.each_object_to_import {}
end
- context 'when github_review_importer_query_only_unimported_merge_requests is disabled' do
- before do
- stub_feature_flags(github_review_importer_query_only_unimported_merge_requests: false)
- end
-
- it 'fetchs the merged pull requests data' do
- merge_request = create(
- :merged_merge_request,
- iid: 999,
- source_project: project,
- target_project: project
- )
-
- review = double
-
- expect(review)
- .to receive(:merge_request_id=)
- .with(merge_request.id)
+ it 'skips cached merge requests' do
+ Gitlab::Cache::Import::Caching.set_add(
+ "github-importer/merge_request/already-imported/#{project.id}",
+ merge_request.id
+ )
- allow(client)
- .to receive(:pull_request_reviews)
- .exactly(:once) # ensure to be cached on the second call
- .with('github/repo', merge_request.iid)
- .and_return([review])
+ expect(review).not_to receive(:merge_request_id=)
- expect { |b| subject.each_object_to_import(&b) }
- .to yield_with_args(review)
+ expect(client).not_to receive(:each_page)
- subject.each_object_to_import {}
- end
+ subject.each_object_to_import {}
end
end
end
diff --git a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb
index 3839303b881..58a8fb1b7e4 100644
--- a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb
@@ -202,7 +202,7 @@ RSpec.describe Gitlab::GithubImport::Importer::RepositoryImporter do
expect(repository)
.to receive(:fetch_as_mirror)
- .with(project.import_url, refmap: Gitlab::GithubImport.refmap, forced: true, remote_name: 'github')
+ .with(project.import_url, refmap: Gitlab::GithubImport.refmap, forced: true)
service = double
expect(Repositories::HousekeepingService)
@@ -211,17 +211,6 @@ RSpec.describe Gitlab::GithubImport::Importer::RepositoryImporter do
expect(importer.import_repository).to eq(true)
end
-
- it 'marks the import as failed when an error was raised' do
- expect(project).to receive(:ensure_repository)
- .and_raise(Gitlab::Git::Repository::NoRepository)
-
- expect(importer)
- .to receive(:fail_import)
- .and_return(false)
-
- expect(importer.import_repository).to eq(false)
- end
end
describe '#import_wiki_repository' do
@@ -234,28 +223,40 @@ RSpec.describe Gitlab::GithubImport::Importer::RepositoryImporter do
expect(importer.import_wiki_repository).to eq(true)
end
- it 'marks the import as failed and creates an empty repo if an error was raised' do
- expect(wiki_repository)
- .to receive(:import_repository)
- .with(importer.wiki_url)
- .and_raise(Gitlab::Git::CommandError)
+ context 'when it raises a Gitlab::Git::CommandError' do
+ context 'when the error is not a "repository not exported"' do
+ it 'creates the wiki and re-raise the exception' do
+ exception = Gitlab::Git::CommandError.new
- expect(importer)
- .to receive(:fail_import)
- .and_return(false)
+ expect(wiki_repository)
+ .to receive(:import_repository)
+ .with(importer.wiki_url)
+ .and_raise(exception)
- expect(project)
- .to receive(:create_wiki)
+ expect(project)
+ .to receive(:create_wiki)
- expect(importer.import_wiki_repository).to eq(false)
- end
- end
+ expect { importer.import_wiki_repository }
+ .to raise_error(exception)
+ end
+ end
+
+ context 'when the error is a "repository not exported"' do
+ it 'returns true' do
+ exception = Gitlab::Git::CommandError.new('repository not exported')
- describe '#fail_import' do
- it 'marks the import as failed' do
- expect(project.import_state).to receive(:mark_as_failed).with('foo')
+ expect(wiki_repository)
+ .to receive(:import_repository)
+ .with(importer.wiki_url)
+ .and_raise(exception)
- expect(importer.fail_import('foo')).to eq(false)
+ expect(project)
+ .not_to receive(:create_wiki)
+
+ expect(importer.import_wiki_repository)
+ .to eq(true)
+ end
+ end
end
end