2015-09-01 07:56:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe RepositoryForkWorker do
|
2017-12-11 11:35:03 +00:00
|
|
|
describe 'modules' do
|
|
|
|
it 'includes ProjectImportOptions' do
|
|
|
|
expect(described_class).to include_module(ProjectImportOptions)
|
|
|
|
end
|
2016-03-18 14:31:19 +00:00
|
|
|
end
|
|
|
|
|
2015-09-01 07:56:40 +00:00
|
|
|
describe "#perform" do
|
2017-12-11 11:35:03 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:fork_project) { create(:project, :repository, :import_scheduled, forked_from_project: project) }
|
|
|
|
let(:shell) { Gitlab::Shell.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:gitlab_shell).and_return(shell)
|
|
|
|
end
|
|
|
|
|
2017-11-30 21:34:31 +00:00
|
|
|
def perform!
|
|
|
|
subject.perform(fork_project.id, '/test/path', project.disk_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_fork_repository
|
|
|
|
expect(shell).to receive(:fork_repository).with(
|
|
|
|
'/test/path',
|
|
|
|
project.disk_path,
|
|
|
|
fork_project.repository_storage_path,
|
|
|
|
fork_project.disk_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-10-10 09:09:49 +00:00
|
|
|
describe 'when a worker was reset without cleanup' do
|
|
|
|
let(:jid) { '12345678' }
|
|
|
|
|
|
|
|
it 'creates a new repository from a fork' do
|
|
|
|
allow(subject).to receive(:jid).and_return(jid)
|
|
|
|
|
2017-11-30 21:34:31 +00:00
|
|
|
expect_fork_repository.and_return(true)
|
|
|
|
|
|
|
|
perform!
|
2017-10-10 09:09:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-01 07:56:40 +00:00
|
|
|
it "creates a new repository from a fork" do
|
2017-11-30 21:34:31 +00:00
|
|
|
expect_fork_repository.and_return(true)
|
2015-09-01 07:56:40 +00:00
|
|
|
|
2017-11-30 21:34:31 +00:00
|
|
|
perform!
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
|
|
|
|
2018-01-14 11:12:43 +00:00
|
|
|
it 'protects the default branch' do
|
|
|
|
expect_fork_repository.and_return(true)
|
|
|
|
|
|
|
|
perform!
|
|
|
|
|
|
|
|
expect(fork_project.protected_branches.first.name).to eq(fork_project.default_branch)
|
|
|
|
end
|
|
|
|
|
2016-03-18 14:31:19 +00:00
|
|
|
it 'flushes various caches' do
|
2017-11-30 21:34:31 +00:00
|
|
|
expect_fork_repository.and_return(true)
|
2016-02-16 16:31:37 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches)
|
|
|
|
.and_call_original
|
2016-02-16 16:31:37 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect_any_instance_of(Repository).to receive(:expire_exists_cache)
|
|
|
|
.and_call_original
|
2016-03-18 14:31:19 +00:00
|
|
|
|
2017-11-30 21:34:31 +00:00
|
|
|
perform!
|
2016-02-16 16:31:37 +00:00
|
|
|
end
|
|
|
|
|
2015-09-01 07:56:40 +00:00
|
|
|
it "handles bad fork" do
|
2017-11-30 21:34:31 +00:00
|
|
|
error_message = "Unable to fork project #{fork_project.id} for repository #{project.full_path} -> #{fork_project.full_path}"
|
2017-06-01 14:27:35 +00:00
|
|
|
|
2017-11-30 21:34:31 +00:00
|
|
|
expect_fork_repository.and_return(false)
|
2016-03-18 14:31:19 +00:00
|
|
|
|
2017-12-11 11:35:03 +00:00
|
|
|
expect { perform! }.to raise_error(StandardError, error_message)
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|