diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-31 06:10:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-31 06:10:23 +0300 |
commit | a5bd90f43bbd7d7b3222cf84698daa2cbc6e2b3f (patch) | |
tree | fb1b7d6018d443f55cad7b876e7ab3b5fe1df83f /spec/workers/gitlab/github_import | |
parent | f97832e536bf561a20b81c07e35884454691dcf8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/gitlab/github_import')
3 files changed, 97 insertions, 1 deletions
diff --git a/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb b/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb new file mode 100644 index 00000000000..cd53c6ee9c0 --- /dev/null +++ b/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::ImportReleaseAttachmentsWorker 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) + end + + let(:client) { instance_double('Gitlab::GithubImport::Client') } + let(:importer) { instance_double('Gitlab::GithubImport::Importer::ReleaseAttachmentsImporter') } + + let(:release_hash) do + { + 'release_db_id' => rand(100), + 'description' => <<-TEXT + Some text... + + ![special-image](https://user-images.githubusercontent.com...) + TEXT + } + end + + it 'imports an issue event' do + expect(Gitlab::GithubImport::Importer::ReleaseAttachmentsImporter) + .to receive(:new) + .with( + an_instance_of(Gitlab::GithubImport::Representation::ReleaseAttachments), + project, + client + ) + .and_return(importer) + + expect(importer).to receive(:execute) + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .and_call_original + + worker.import(project, client, release_hash) + end + end +end 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 new file mode 100644 index 00000000000..afed0debd90 --- /dev/null +++ b/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Stage::ImportAttachmentsWorker do + subject(:worker) { described_class.new } + + let(:project) { create(:project) } + let!(:group) { create(:group, projects: [project]) } + let(:feature_flag_state) { [group] } + + describe '#import' do + let(:importer) { instance_double('Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter') } + let(:client) { instance_double('Gitlab::GithubImport::Client') } + + before do + stub_feature_flags(github_importer_attachments_import: feature_flag_state) + end + + it 'imports release attachments' do + waiter = Gitlab::JobWaiter.new(2, '123') + + expect(Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter) + .to receive(:new) + .with(project, client) + .and_return(importer) + + expect(importer).to receive(:execute).and_return(waiter) + + expect(Gitlab::GithubImport::AdvanceStageWorker) + .to receive(:perform_async) + .with(project.id, { '123' => 2 }, :lfs_objects) + + worker.import(client, project) + end + + context 'when feature flag is disabled' do + let(:feature_flag_state) { false } + + it 'skips release attachments import and calls next stage' do + expect(Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter).not_to receive(:new) + expect(Gitlab::GithubImport::AdvanceStageWorker).to receive(:perform_async).with(project.id, {}, :lfs_objects) + + worker.import(client, project) + end + 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 f9f21e4dfa2..adf20d24a7e 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 @@ -26,7 +26,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportNotesWorker do expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) - .with(project.id, { '123' => 2 }, :lfs_objects) + .with(project.id, { '123' => 2 }, :attachments) worker.import(client, project) end |