diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-08 09:07:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-08 09:07:45 +0300 |
commit | 14ac28d7c7fcf1aba321f521f3a980b03b7b090e (patch) | |
tree | 1b60bc1655ad728c5e2fa6a2f1aeda35358f8e56 /spec/workers/gitlab/github_import | |
parent | bdf7b581f80cf7119528eab0ac31e2c549563872 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/gitlab/github_import')
3 files changed, 90 insertions, 2 deletions
diff --git a/spec/workers/gitlab/github_import/import_collaborator_worker_spec.rb b/spec/workers/gitlab/github_import/import_collaborator_worker_spec.rb new file mode 100644 index 00000000000..b9463fb9a2d --- /dev/null +++ b/spec/workers/gitlab/github_import/import_collaborator_worker_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::ImportCollaboratorWorker, feature_category: :importers do + let(:worker) { described_class.new } + + describe '#import' do + let(:project) do + instance_double('Project', full_path: 'foo/bar', id: 1, import_state: import_state) + end + + let(:import_state) { build_stubbed(:import_state, :started) } + let(:client) { instance_double('Gitlab::GithubImport::Client') } + let(:importer) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') } + + it 'imports a collaborator' do + expect(Gitlab::GithubImport::Importer::CollaboratorImporter) + .to receive(:new) + .with( + an_instance_of(Gitlab::GithubImport::Representation::Collaborator), + project, + client + ) + .and_return(importer) + + expect(importer).to receive(:execute) + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .and_call_original + + worker.import( + project, client, { 'id' => 100500, 'login' => 'alice', 'role_name' => 'maintainer' } + ) + end + end +end 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 new file mode 100644 index 00000000000..d71184d87d9 --- /dev/null +++ b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +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(:worker) { described_class.new } + let(:importer) { instance_double(Gitlab::GithubImport::Importer::CollaboratorsImporter) } + let(:client) { instance_double(Gitlab::GithubImport::Client) } + + describe '#import' do + it 'imports all the pull requests' do + waiter = Gitlab::JobWaiter.new(2, '123') + + expect(Gitlab::GithubImport::Importer::CollaboratorsImporter) + .to receive(:new) + .with(project, client) + .and_return(importer) + expect(importer).to receive(:execute).and_return(waiter) + + expect(import_state).to receive(:refresh_jid_expiration) + + expect(Gitlab::GithubImport::AdvanceStageWorker) + .to receive(:perform_async) + .with(project.id, { '123' => 2 }, :pull_requests_merged_by) + + worker.import(client, project) + end + end + + it 'raises an error' do + exception = StandardError.new('_some_error_') + + expect_next_instance_of(Gitlab::GithubImport::Importer::CollaboratorsImporter) do |importer| + expect(importer).to receive(:execute).and_raise(exception) + end + expect(Gitlab::Import::ImportFailureService).to receive(:track) + .with( + project_id: project.id, + exception: exception, + error_source: described_class.name, + fail_import: true, + metrics: true + ).and_call_original + + expect { worker.import(client, project) }.to raise_error(StandardError) + end +end 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 b18b5ce64d1..6ebf93730eb 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do +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) } @@ -28,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) - .with(project.id, { '123' => 2 }, :pull_requests_merged_by) + .with(project.id, { '123' => 2 }, :collaborators) worker.import(client, project) end |