diff options
Diffstat (limited to 'spec/workers/gitlab')
17 files changed, 156 insertions, 59 deletions
diff --git a/spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb b/spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb index d4cd1b82349..1141d08729d 100644 --- a/spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb +++ b/spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb @@ -3,7 +3,14 @@ require 'spec_helper' RSpec.describe Gitlab::BitbucketServerImport::Stage::ImportUsersWorker, feature_category: :importers do - let_it_be(:project) { create(:project, :import_started) } + let_it_be(:project) do + create(:project, :import_started, + import_data_attributes: { + data: { 'project_key' => 'key', 'repo_slug' => 'slug' }, + credentials: { 'base_uri' => 'http://bitbucket.org/', 'user' => 'bitbucket', 'password' => 'password' } + } + ) + end let(:worker) { described_class.new } @@ -15,6 +22,12 @@ RSpec.describe Gitlab::BitbucketServerImport::Stage::ImportUsersWorker, feature_ allow_next_instance_of(Gitlab::BitbucketServerImport::Importers::UsersImporter) do |importer| allow(importer).to receive(:execute) end + + allow(Gitlab::BitbucketServerImport::Stage::ImportPullRequestsWorker).to receive(:perform_async).and_return(nil) + end + + it_behaves_like 'an idempotent worker' do + let(:job_args) { [project.id] } end it 'schedules the next stage' do diff --git a/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb index aa8243154ef..cbe27934bd5 100644 --- a/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb @@ -5,16 +5,13 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker, feature_category: :importers do subject(:worker) { described_class.new } - describe '#import' do - let(:import_state) { create(:import_state, :started) } - - let(:project) do - instance_double('Project', full_path: 'foo/bar', id: 1, import_state: import_state) + describe '#execute' do + let_it_be(:project) do + create(:project, import_url: 'https://github.com/foo/bar.git', import_state: create(:import_state, :started)) end - let(:client) { instance_double('Gitlab::GithubImport::Client') } - let(:importer) { instance_double('Gitlab::GithubImport::Importer::IssueEventImporter') } - + let(:client) { instance_double(Gitlab::GithubImport::Client) } + let(:extended_events) { true } let(:event_hash) do { 'id' => 6501124486, @@ -29,23 +26,55 @@ RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker, feature_category: : } end - it 'imports an issue event' do - expect(Gitlab::GithubImport::Importer::IssueEventImporter) - .to receive(:new) - .with( - an_instance_of(Gitlab::GithubImport::Representation::IssueEvent), - project, - client - ) - .and_return(importer) + before do + allow_next_instance_of(Gitlab::GithubImport::Settings) do |setting| + allow(setting).to receive(:extended_events?).and_return(extended_events) + end + end - expect(importer).to receive(:execute) + it 'imports an issue event and increase importer counter' do + expect_next_instance_of(Gitlab::GithubImport::Importer::IssueEventImporter, + an_instance_of(Gitlab::GithubImport::Representation::IssueEvent), + project, + client + ) do |importer| + expect(importer).to receive(:execute) + end expect(Gitlab::GithubImport::ObjectCounter) .to receive(:increment) + .with(project, :issue_event, :imported) .and_call_original worker.import(project, client, event_hash) end + + context 'when event should increment a mapped importer counter' do + before do + stub_const('Gitlab::GithubImport::Importer::IssueEventImporter::EVENT_COUNTER_MAP', { + 'closed' => 'custom_type' + }) + + allow_next_instance_of(Gitlab::GithubImport::Importer::IssueEventImporter) do |importer| + allow(importer).to receive(:execute) + end + end + + it 'increments the mapped importer counter' do + expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, 'custom_type', :imported) + + worker.import(project, client, event_hash) + end + + context 'when extended_events is disabled' do + let(:extended_events) { false } + + it 'increments the issue_event importer counter' do + expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, :issue_event, :imported) + + worker.import(project, client, event_hash) + end + end + end end end diff --git a/spec/workers/gitlab/github_import/replay_events_worker_spec.rb b/spec/workers/gitlab/github_import/replay_events_worker_spec.rb new file mode 100644 index 00000000000..99c9e838bbf --- /dev/null +++ b/spec/workers/gitlab/github_import/replay_events_worker_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::ReplayEventsWorker, feature_category: :importers do + let_it_be(:project) { create(:project, import_state: create(:import_state, :started)) } + let(:client) { instance_double(Gitlab::GithubImport::Client) } + + let(:worker) { described_class.new } + + describe '#import' do + it 'call replay events importer' do + hash = { + 'issuable_iid' => 1, + 'issuable_type' => 'Issue' + } + + expect_next_instance_of(Gitlab::GithubImport::Importer::ReplayEventsImporter, + an_instance_of(Gitlab::GithubImport::Representation::ReplayEvent), project, client) do |importer| + expect(importer).to receive(:execute) + end + + expect(Gitlab::GithubImport::ObjectCounter).not_to receive(:increment) + + worker.import(project, client, hash) + end + end + + describe '#object_type' do + it { expect(worker.object_type).to eq(:replay_event) } + end +end diff --git a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb index 6d8fa29bd27..ba8fcdb2406 100644 --- a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb @@ -3,8 +3,9 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::FinishImportWorker, feature_category: :importers do - let(:project) { create(:project) } - let(:worker) { described_class.new } + let_it_be(:project) { create(:project) } + + subject(:worker) { described_class.new } it_behaves_like Gitlab::GithubImport::StageMethods diff --git a/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb index c8b528593b9..75c9ab96751 100644 --- a/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb @@ -3,12 +3,13 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportAttachmentsWorker, feature_category: :importers do - subject(:worker) { described_class.new } - let_it_be(:project) { create(:project) } - let(:settings) { ::Gitlab::GithubImport::Settings.new(project) } + + let(:settings) { ::Gitlab::GithubImport::Settings.new(project.reload) } let(:stage_enabled) { true } + subject(:worker) { described_class.new } + before do settings.write({ optional_stages: { attachments_import: stage_enabled } }) end diff --git a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb index b8f2db8e2d9..49dc905f430 100644 --- a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb @@ -4,12 +4,12 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportBaseDataWorker, feature_category: :importers do let_it_be(:project) { create(:project) } - let_it_be(:import_state) { create(:import_state, project: project) } - let(:worker) { described_class.new } let(:importer) { double(:importer) } let(:client) { double(:client) } + subject(:worker) { described_class.new } + it_behaves_like Gitlab::GithubImport::StageMethods describe '#import' do diff --git a/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb index 6a55f575da8..7a085227b36 100644 --- a/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb @@ -4,14 +4,14 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportCollaboratorsWorker, feature_category: :importers do let_it_be(:project) { create(:project) } - let_it_be(:import_state) { create(:import_state, project: project) } + let(:settings) { Gitlab::GithubImport::Settings.new(project) } let(:stage_enabled) { true } - - let(:worker) { described_class.new } let(:importer) { instance_double(Gitlab::GithubImport::Importer::CollaboratorsImporter) } let(:client) { instance_double(Gitlab::GithubImport::Client) } + subject(:worker) { described_class.new } + it_behaves_like Gitlab::GithubImport::StageMethods describe '#import' do diff --git a/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb index bad3a5beb0e..6b01f2825e4 100644 --- a/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb @@ -3,15 +3,19 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker, feature_category: :importers do - subject(:worker) { described_class.new } + let_it_be(:project) { create(:project) } - let(:project) { create(:project) } let!(:group) { create(:group, projects: [project]) } - let(:settings) { ::Gitlab::GithubImport::Settings.new(project) } + let(:settings) { ::Gitlab::GithubImport::Settings.new(project.reload) } let(:stage_enabled) { true } + let(:extended_events) { false } + + subject(:worker) { described_class.new } before do - settings.write({ optional_stages: { single_endpoint_issue_events_import: stage_enabled } }) + settings.write({ + optional_stages: { single_endpoint_issue_events_import: stage_enabled }, extended_events: extended_events + }) end it_behaves_like Gitlab::GithubImport::StageMethods @@ -48,6 +52,18 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker, feature_cat worker.import(client, project) end + + context 'when extended_events is enabled' do + let(:extended_events) { true } + + it 'does not skip the stage' do + expect_next_instance_of(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter) do |importer| + expect(importer).to receive(:execute).and_return(Gitlab::JobWaiter.new) + end + + worker.import(client, project) + end + end end end end diff --git a/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb index 10f6ebfbab9..bc829e6124c 100644 --- a/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb @@ -3,12 +3,13 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker, feature_category: :importers do - let(:project) { create(:project) } - let(:worker) { described_class.new } + let_it_be(:project) { create(:project) } - let(:settings) { ::Gitlab::GithubImport::Settings.new(project) } + let(:settings) { ::Gitlab::GithubImport::Settings.new(project.reload) } let(:single_endpoint_optional_stage) { true } + subject(:worker) { described_class.new } + before do settings.write({ optional_stages: { single_endpoint_notes_import: single_endpoint_optional_stage } }) end diff --git a/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb index 40194a91b3a..a0b2f82f378 100644 --- a/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb @@ -3,14 +3,16 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportLfsObjectsWorker, feature_category: :importers do - let(:project) { create(:project) } - let(:worker) { described_class.new } + let_it_be(:project) { create(:project) } + + subject(:worker) { described_class.new } it_behaves_like Gitlab::GithubImport::StageMethods describe '#import' do it 'imports all the lfs objects' do - importer = double(:importer) + importer = instance_double(Gitlab::GithubImport::Importer::LfsObjectsImporter) + client = instance_double(Gitlab::GithubImport::Client) waiter = Gitlab::JobWaiter.new(2, '123') expect(Gitlab::GithubImport::Importer::LfsObjectsImporter) @@ -26,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportLfsObjectsWorker, feature_cate .to receive(:perform_async) .with(project.id, { '123' => 2 }, 'finish') - worker.import(project) + worker.import(client, project) end end end diff --git a/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb index 69078a666a5..a8b40ff43d2 100644 --- a/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb @@ -3,12 +3,13 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportNotesWorker, feature_category: :importers do - let(:project) { create(:project) } - let(:worker) { described_class.new } + let_it_be(:project) { create(:project) } - let(:settings) { ::Gitlab::GithubImport::Settings.new(project) } + let(:settings) { ::Gitlab::GithubImport::Settings.new(project.reload) } let(:single_endpoint_optional_stage) { true } + subject(:worker) { described_class.new } + before do settings.write({ optional_stages: { single_endpoint_notes_import: single_endpoint_optional_stage } }) end diff --git a/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb index b73f8c6524d..dcc6b3d2311 100644 --- a/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb @@ -4,12 +4,12 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportProtectedBranchesWorker, feature_category: :importers do let_it_be(:project) { create(:project) } - let_it_be(:import_state) { create(:import_state, project: project) } - let(:worker) { described_class.new } let(:importer) { instance_double('Gitlab::GithubImport::Importer::ProtectedBranchImporter') } let(:client) { instance_double('Gitlab::GithubImport::Client') } + subject(:worker) { described_class.new } + it_behaves_like Gitlab::GithubImport::StageMethods describe '#import' do diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb index b214f6a97d4..b3cb73c5fa0 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker, feature_category: :importers do - let(:project) { create(:project) } - let(:import_state) { create(:import_state, project: project) } - let(:worker) { described_class.new } + let_it_be(:project) { create(:project) } + + subject(:worker) { described_class.new } it_behaves_like Gitlab::GithubImport::StageMethods diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb index 4468de7e691..c7b73357e76 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewRequestsWorker, feature_category: :importers do - subject(:worker) { described_class.new } + let_it_be(:project) { create(:project) } - let(:project) { instance_double(Project, id: 1, import_state: import_state) } - let(:import_state) { instance_double(ProjectImportState) } let(:client) { instance_double(Gitlab::GithubImport::Client) } let(:importer) { instance_double(Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImporter) } let(:waiter) { Gitlab::JobWaiter.new(2, '123') } + subject(:worker) { described_class.new } + it_behaves_like Gitlab::GithubImport::StageMethods describe '#import' do diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb index 48b41435adb..ab3f0b43304 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb @@ -3,11 +3,12 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker, feature_category: :importers do - let(:project) { create(:project) } - let(:import_state) { create(:import_state, project: project) } - let(:worker) { described_class.new } + let_it_be(:project) { create(:project) } + let(:client) { double(:client) } + subject(:worker) { described_class.new } + it_behaves_like Gitlab::GithubImport::StageMethods describe '#import' do diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb index 2ea66d8cdf3..2c1beb29fa1 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb @@ -4,13 +4,13 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker, feature_category: :importers do let_it_be(:project) { create(:project) } - let_it_be(:import_state) { create(:import_state, project: project) } - let(:options) { { state: 'all', sort: 'number', direction: 'desc', per_page: '1' } } - let(:worker) { described_class.new } + let(:options) { { state: 'all', sort: 'number', direction: 'desc', per_page: '1' } } let(:importer) { double(:importer) } let(:client) { double(:client) } + subject(:worker) { described_class.new } + it_behaves_like Gitlab::GithubImport::StageMethods describe '#import' do diff --git a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb index 020f7539bf4..e61b46124b3 100644 --- a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker, feature_category: :importers do - let_it_be(:project) { create(:project, :import_started) } + let_it_be(:project) { create(:project) } - let(:worker) { described_class.new } + subject(:worker) { described_class.new } it_behaves_like Gitlab::GithubImport::StageMethods |