2015-09-01 07:56:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe RepositoryForkWorker do
|
2017-06-01 14:27:35 +00:00
|
|
|
let(:project) { create(:project, :repository, :import_scheduled) }
|
2017-03-27 20:42:08 +00:00
|
|
|
let(:fork_project) { create(:project, :repository, forked_from_project: project) }
|
2016-03-18 14:31:19 +00:00
|
|
|
let(:shell) { Gitlab::Shell.new }
|
2015-09-01 07:56:40 +00:00
|
|
|
|
2017-05-01 15:13:33 +00:00
|
|
|
subject { described_class.new }
|
2015-09-01 07:56:40 +00:00
|
|
|
|
2016-03-18 14:31:19 +00:00
|
|
|
before do
|
|
|
|
allow(subject).to receive(:gitlab_shell).and_return(shell)
|
|
|
|
end
|
|
|
|
|
2015-09-01 07:56:40 +00:00
|
|
|
describe "#perform" do
|
|
|
|
it "creates a new repository from a fork" do
|
2016-03-18 14:31:19 +00:00
|
|
|
expect(shell).to receive(:fork_repository).with(
|
2016-07-26 21:22:13 +00:00
|
|
|
'/test/path',
|
2017-02-23 23:55:01 +00:00
|
|
|
project.full_path,
|
2016-07-26 21:22:13 +00:00
|
|
|
project.repository_storage_path,
|
2017-02-23 23:55:01 +00:00
|
|
|
fork_project.namespace.full_path
|
2015-12-15 02:53:52 +00:00
|
|
|
).and_return(true)
|
2015-09-01 07:56:40 +00:00
|
|
|
|
2015-12-15 02:53:52 +00:00
|
|
|
subject.perform(
|
|
|
|
project.id,
|
2016-07-26 21:22:13 +00:00
|
|
|
'/test/path',
|
2017-02-23 23:55:01 +00:00
|
|
|
project.full_path,
|
|
|
|
fork_project.namespace.full_path)
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
|
|
|
|
2016-03-18 14:31:19 +00:00
|
|
|
it 'flushes various caches' do
|
2016-06-22 21:04:51 +00:00
|
|
|
expect(shell).to receive(:fork_repository).with(
|
2016-07-26 21:22:13 +00:00
|
|
|
'/test/path',
|
2017-02-23 23:55:01 +00:00
|
|
|
project.full_path,
|
2016-07-26 21:22:13 +00:00
|
|
|
project.repository_storage_path,
|
2017-02-23 23:55:01 +00:00
|
|
|
fork_project.namespace.full_path
|
2016-06-22 21:04:51 +00:00
|
|
|
).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-02-23 23:55:01 +00:00
|
|
|
subject.perform(project.id, '/test/path', project.full_path,
|
|
|
|
fork_project.namespace.full_path)
|
2016-02-16 16:31:37 +00:00
|
|
|
end
|
|
|
|
|
2015-09-01 07:56:40 +00:00
|
|
|
it "handles bad fork" do
|
2017-06-01 14:27:35 +00:00
|
|
|
source_path = project.full_path
|
|
|
|
target_path = fork_project.namespace.full_path
|
|
|
|
error_message = "Unable to fork project #{project.id} for repository #{source_path} -> #{target_path}"
|
|
|
|
|
2016-03-18 14:31:19 +00:00
|
|
|
expect(shell).to receive(:fork_repository).and_return(false)
|
|
|
|
|
2017-06-01 14:27:35 +00:00
|
|
|
expect do
|
|
|
|
subject.perform(project.id, '/test/path', source_path, target_path)
|
|
|
|
end.to raise_error(RepositoryForkWorker::ForkError, error_message)
|
|
|
|
end
|
2016-03-18 14:31:19 +00:00
|
|
|
|
2017-06-01 14:27:35 +00:00
|
|
|
it 'handles unexpected error' do
|
|
|
|
source_path = project.full_path
|
|
|
|
target_path = fork_project.namespace.full_path
|
|
|
|
|
|
|
|
allow_any_instance_of(Gitlab::Shell).to receive(:fork_repository).and_raise(RuntimeError)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
subject.perform(project.id, '/test/path', source_path, target_path)
|
|
|
|
end.to raise_error(RepositoryForkWorker::ForkError)
|
|
|
|
expect(project.reload.import_status).to eq('failed')
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|