debian-mirror-gitlab/spec/workers/repository_fork_worker_spec.rb

73 lines
2.3 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
require 'spec_helper'
describe RepositoryForkWorker do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :repository, :import_scheduled) }
2017-08-17 22:00:37 +05:30
let(:fork_project) { create(:project, :repository, forked_from_project: project) }
2016-06-02 11:05:42 +05:30
let(:shell) { Gitlab::Shell.new }
2015-09-25 12:07:36 +05:30
2017-08-17 22:00:37 +05:30
subject { described_class.new }
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
before do
allow(subject).to receive(:gitlab_shell).and_return(shell)
end
2015-09-25 12:07:36 +05:30
describe "#perform" do
it "creates a new repository from a fork" do
2016-06-02 11:05:42 +05:30
expect(shell).to receive(:fork_repository).with(
2016-08-24 12:49:21 +05:30
'/test/path',
2017-08-17 22:00:37 +05:30
project.full_path,
2016-08-24 12:49:21 +05:30
project.repository_storage_path,
2017-08-17 22:00:37 +05:30
fork_project.namespace.full_path
2015-12-23 02:04:40 +05:30
).and_return(true)
2015-09-25 12:07:36 +05:30
2015-12-23 02:04:40 +05:30
subject.perform(
project.id,
2016-08-24 12:49:21 +05:30
'/test/path',
2017-08-17 22:00:37 +05:30
project.full_path,
fork_project.namespace.full_path)
2015-09-25 12:07:36 +05:30
end
2016-06-02 11:05:42 +05:30
it 'flushes various caches' do
2016-08-24 12:49:21 +05:30
expect(shell).to receive(:fork_repository).with(
'/test/path',
2017-08-17 22:00:37 +05:30
project.full_path,
2016-08-24 12:49:21 +05:30
project.repository_storage_path,
2017-08-17 22:00:37 +05:30
fork_project.namespace.full_path
2016-08-24 12:49:21 +05:30
).and_return(true)
2016-04-02 18:10:28 +05:30
2017-09-10 17:25:29 +05:30
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches)
.and_call_original
2016-04-02 18:10:28 +05:30
2017-09-10 17:25:29 +05:30
expect_any_instance_of(Repository).to receive(:expire_exists_cache)
.and_call_original
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
subject.perform(project.id, '/test/path', project.full_path,
fork_project.namespace.full_path)
2016-04-02 18:10:28 +05:30
end
2015-09-25 12:07:36 +05:30
it "handles bad fork" do
2017-09-10 17:25:29 +05:30
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-06-02 11:05:42 +05:30
expect(shell).to receive(:fork_repository).and_return(false)
2017-09-10 17:25:29 +05:30
expect do
subject.perform(project.id, '/test/path', source_path, target_path)
end.to raise_error(RepositoryForkWorker::ForkError, error_message)
end
2016-06-02 11:05:42 +05:30
2017-09-10 17:25:29 +05:30
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-25 12:07:36 +05:30
end
end
end