1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportAttachmentsWorker do
subject(:worker) { described_class.new }
let_it_be(:project) { create(:project) }
let(:settings) { ::Gitlab::GithubImport::Settings.new(project) }
let(:stage_enabled) { true }
before do
settings.write({ attachments_import: stage_enabled })
end
describe '#import' do
let(:client) { instance_double('Gitlab::GithubImport::Client') }
let(:importers) do
[
{
klass: Gitlab::GithubImport::Importer::Attachments::ReleasesImporter,
double: instance_double('Gitlab::GithubImport::Importer::Attachments::ReleasesImporter'),
waiter: Gitlab::JobWaiter.new(2, '123')
},
{
klass: Gitlab::GithubImport::Importer::Attachments::NotesImporter,
double: instance_double('Gitlab::GithubImport::Importer::Attachments::NotesImporter'),
waiter: Gitlab::JobWaiter.new(3, '234')
},
{
klass: Gitlab::GithubImport::Importer::Attachments::IssuesImporter,
double: instance_double('Gitlab::GithubImport::Importer::Attachments::IssuesImporter'),
waiter: Gitlab::JobWaiter.new(4, '345')
},
{
klass: Gitlab::GithubImport::Importer::Attachments::MergeRequestsImporter,
double: instance_double('Gitlab::GithubImport::Importer::Attachments::MergeRequestsImporter'),
waiter: Gitlab::JobWaiter.new(5, '456')
}
]
end
it 'imports attachments' do
importers.each do |importer|
expect_next_instance_of(importer[:klass], project, client) do |instance|
expect(instance).to receive(:execute).and_return(importer[:waiter])
end
end
expect(Gitlab::GithubImport::AdvanceStageWorker)
.to receive(:perform_async)
.with(project.id, { '123' => 2, '234' => 3, '345' => 4, '456' => 5 }, :protected_branches)
worker.import(client, project)
end
context 'when stage is disabled' do
let(:stage_enabled) { false }
it 'skips release attachments import and calls next stage' do
importers.each { |importer| expect(importer[:klass]).not_to receive(:new) }
expect(Gitlab::GithubImport::AdvanceStageWorker)
.to receive(:perform_async).with(project.id, {}, :protected_branches)
worker.import(client, project)
end
end
end
end
|