Newer
Older
Stan Hu
committed
require 'spec_helper'
describe RepositoryForkWorker do
let(:project) { create(:project, :repository, :import_scheduled) }
let(:fork_project) { create(:project, :repository, forked_from_project: project) }
Stan Hu
committed
subject { described_class.new }
Stan Hu
committed
before do
allow(subject).to receive(:gitlab_shell).and_return(shell)
end
Stan Hu
committed
describe "#perform" do
it "creates a new repository from a fork" do
expect(shell).to receive(:fork_repository).with(
Alejandro Rodríguez
committed
'/test/path',
project.full_path,
Alejandro Rodríguez
committed
project.repository_storage_path,
fork_project.namespace.full_path
Stan Hu
committed
Alejandro Rodríguez
committed
'/test/path',
project.full_path,
fork_project.namespace.full_path)
Stan Hu
committed
end
expect(shell).to receive(:fork_repository).with(
Alejandro Rodríguez
committed
'/test/path',
project.full_path,
Alejandro Rodríguez
committed
project.repository_storage_path,
fork_project.namespace.full_path
).and_return(true)
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches)
.and_call_original
expect_any_instance_of(Repository).to receive(:expire_exists_cache)
.and_call_original
subject.perform(project.id, '/test/path', project.full_path,
fork_project.namespace.full_path)
Stan Hu
committed
it "handles bad fork" do
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}"
expect(shell).to receive(:fork_repository).and_return(false)
expect do
subject.perform(project.id, '/test/path', source_path, target_path)
end.to raise_error(RepositoryForkWorker::ForkError, error_message)
end
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')
Stan Hu
committed
end
end
end